Title: url_shorten
Published: April 25, 2014
Last modified: February 24, 2026

---

# url_shorten( string $url, int $length = 35 ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#wp--skip-link--target)

Shortens a URL, to be used as link text.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#parameters)󠁿

 `$url`stringrequired

URL to shorten.

`$length`intoptional

Maximum length of the shortened URL. Default 35 characters.

Default:`35`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#return)󠁿

 string Shortened URL.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#source)󠁿

    ```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 ) . '&hellip;';
    	}
    	return $short_url;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/formatting.php#L6228)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/formatting.php#L6228-L6236)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#related)󠁿

| Uses | Description | 
| [untrailingslashit()](https://developer.wordpress.org/reference/functions/untrailingslashit/)`wp-includes/formatting.php` |

Removes trailing forward slashes and backslashes if they exist.

  |

| Used by | Description | 
| [WP_Links_List_Table::column_url()](https://developer.wordpress.org/reference/classes/wp_links_list_table/column_url/)`wp-admin/includes/class-wp-links-list-table.php` |

Handles the link URL column output.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/url_shorten/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Moved to wp-includes/formatting.php from wp-admin/includes/misc.php and added $length param. | 
| [1.2.0](https://developer.wordpress.org/reference/since/1.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Furl_shorten%2F)
before being able to contribute a note or feedback.