WordPress at a glance
function is not described

_truncate_post_slug() WP 3.6.0

Truncate a post slug.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

String. The truncated slug.

Usage

_truncate_post_slug( $slug, $length );
$slug(string) (required)
The slug to truncate.
$length(int)
Max length of the slug.
Default: 200 (characters)

Notes

  • See: utf8_uri_encode()

Changelog

Since 3.6.0 Introduced.

Code of _truncate_post_slug() WP 5.7

<?php
function _truncate_post_slug( $slug, $length = 200 ) {
	if ( strlen( $slug ) > $length ) {
		$decoded_slug = urldecode( $slug );
		if ( $decoded_slug === $slug ) {
			$slug = substr( $slug, 0, $length );
		} else {
			$slug = utf8_uri_encode( $decoded_slug, $length );
		}
	}

	return rtrim( $slug, '-' );
}