_truncate_post_slug

函数


_truncate_post_slug ( $slug, $length = 200 )
Access
Private
参数
  • (string)
    $slug
    The slug to truncate.
    Required:
  • (int)
    $length
    Optional. Max length of the slug. Default 200 (characters).
    Required:
    Default: 200
返回值
  • (string) The truncated slug.
相关
  • utf8_uri_encode()
定义位置
  • wp-includes/post.php
    , line 5171
引入
3.6.0
弃用

Truncates a post slug.

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