Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use utf8_uri_encode() instead.

_truncate_post_slug() WordPress Function

The truncate_post_slug() function is used to truncate a post slug. This function is useful when you want to create a shorter slug for a post.

_truncate_post_slug( string $slug, int $length = 200 ) #

Truncate a post slug.


Description

Top ↑

See also


Top ↑

Parameters

$slug

(string)(Required)The slug to truncate.

$length

(int)(Optional) Max length of the slug. Default 200 (characters).

Default value: 200


Top ↑

Return

(string) The truncated slug.


Top ↑

Source

File: wp-includes/post.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, true );
		}
	}

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


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More