url_shorten()
Shorten a URL, to be used as link text.
No Hooks.
Return
String
. Shortened URL.
Usage
url_shorten( $url, $length );
- $url(string) (required)
- URL to shorten.
- $length(int)
- Maximum length of the shortened URL.
Default: 35 characters
Changelog
Since 1.2.0 | Introduced. |
Since 4.4.0 | Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param. |
Code of url_shorten() url shorten WP 6.0
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; }