url_shorten() – Shorten a URL, to be used as link text.

You appear to be a bot. Output may be restricted

Description

Shortens a URL, to be used as link text.

Usage

$string = url_shorten( $url, $length );

Parameters

$url
( string ) required – URL to shorten.
$length
( int ) optional default: 35 – Optional. Maximum length of the shortened URL. Default 35 characters.

Returns

string Shortened URL.

Source

File name: wordpress/wp-includes/formatting.php
Lines:

1 to 9 of 9
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;
}
 

 View on GitHub View on Trac