WordPress开发者和主题制作者的搜索引擎



url_shorten ›

Since1.2.0
已弃用n/a
url_shorten ( $url, $length = 35 )
参数: (2)
  • (string) $url URL to shorten.
    Required: Yes
  • (int) $length Optional. Maximum length of the shortened URL. Default 35 characters.
    Required: No
    默认: 35
返回:
  • (string) Shortened URL.
定义在:
文档:
Change Log:
  • 4.4.0

Shorten a URL, to be used as link text.



源码

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;
}