On this page
url_shorten( string $url, int $length = 35 ): string
Shortens a URL, to be used as link text.
Parameters
$urlstring Required-
URL to shorten.
$lengthint Optional-
Maximum length of the shortened URL. Default 35 characters.
Default:
35
Return
string Shortened URL.
Source
File: wp-includes/formatting.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| untrailingslashit() wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. |
Used By
| Used By | Description |
|---|---|
| WP_Links_List_Table::column_url() wp-admin/includes/class-wp-links-list-table.php | Handles the link URL column output. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/url_shorten