wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema



wp_truncate_slug › WordPress Function

Desde7.2.0
Obsoleton/a
› wp_truncate_slug ( $slug, $length = 200 )
Acesso:
  • private
Parâmetros: (2)
  • (string) $slug The slug to truncate.
    Required: Yes
  • (int) $length Optional. Max length of the slug. Default 200 (characters).
    Required: No
    Padrão: 200
Ver:
Retorna:
  • (string) The truncated slug.
Definido em:
Codex:

Truncates a slug to a given length.

Non-ASCII slugs are stored percent-encoded, so the slug is truncated on a character boundary to avoid cutting a percent-encoded sequence in half.


Fonte

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