A WordPress-centric search engine for devs and theme authors



_truncate_post_slug ›

Since3.6.0
Deprecatedn/a
_truncate_post_slug ( $slug, $length = 200 )
Access:
  • private
Parameters: (2)
  • (string) $slug The slug to truncate.
    Required: Yes
  • (int) $length Optional. Max length of the slug. Default 200 (characters).
    Required: No
    Default: 200
See:
Returns:
  • (string) The truncated slug.
Defined at:
Codex:

Truncate a post slug.



Source

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, '-' );
}