Uses
Uses | Description |
---|---|
wp-includes/formatting.php: untrailingslashit() | Removes trailing forward slashes and backslashes if they exist. |
Shorten a URL, to be used as link text.
(string) (Required) URL to shorten.
(int) (Optional) Maximum length of the shortened URL. Default 35 characters.
Default value: 35
(string) Shortened URL.
File: wp-includes/formatting.php
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; }
Version | Description |
---|---|
4.4.0 | Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param. |
1.2.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/url_shorten