url_shorten

函式
url_shorten ( $url, $length = 35 )
引數
  • (string) $url URL to shorten.
    Required:
  • (int) $length Optional. Maximum length of the shortened URL. Default 35 characters.
    Required:
    Default: 35
返回值
  • (string) Shortened URL.
定義位置
相關方法
do_shortcodesort_menuremove_shortcodeapply_shortcodesstrip_shortcodes
引入
1.2.0
棄用
-

url_shorten: 這個函式使用WordPress.com的URL縮短器服務縮短一個給定的URL。

縮短一個URL,作為連結文字使用。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >