Un motore di ricerca WordPress per sviluppatori e autori di temi



url_shorten ›

Da1.2.0
Deprecaton/a
url_shorten ( $url, $length = 35 )
Parametri: (2)
  • (string) $url URL to shorten.
    Richiesto:
  • (int) $length Optional. Maximum length of the shortened URL. Default 35 characters.
    Richiesto: No
    Default: 35
Ritorna:
  • (string) Shortened URL.
Definito a:
Codex:
ChangeLog:
  • 4.4.0

Shorten a URL, to be used as link text.



Sorgenti

function url_shorten( $url, $length = 35 ) {
	$stripped  = str_replace( array( 'https://', 'http://', 'www.' ), '', $url );
	$short_url = untrailingslashit( $stripped );

	if ( strlen( $short_url ) > $length ) {
		$short_url = substr( $short_url, 0, $length - 3 ) . '…';
	}
	return $short_url;
}