Shortens a URL, to be used as link text.
Parameters
$url
stringrequired- URL to shorten.
$length
intoptional- Maximum length of the shortened URL. Default 35 characters.
Default:
35
Source
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;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.