_truncate_post_slug()
Truncates a post slug.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
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. |
_truncate_post_slug() truncate post slug code WP 6.9.1
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, true );
}
}
return rtrim( $slug, '-' );
}