strip_fragment_from_url

函式
strip_fragment_from_url ( $url )
引數
  • (string) $url The URL to strip.
    Required:
返回值
  • (string) The altered URL.
定義位置
相關方法
get_home_urlstripslashes_from_strings_onlyget_blog_id_from_urliframe_footerrest_get_avatar_urls
引入
4.4.0
棄用
-

strip_fragment_from_url: 這是一個WordPress的函式,從一個URL中刪除片段。它接受一個引數,$url,並返回沒有片段的URL。

如果URL中存在#fragment,則將其刪除。

function strip_fragment_from_url( $url ) {
	$parsed_url = wp_parse_url( $url );

	if ( ! empty( $parsed_url['host'] ) ) {
		$url = '';

		if ( ! empty( $parsed_url['scheme'] ) ) {
			$url = $parsed_url['scheme'] . ':';
		}

		$url .= '//' . $parsed_url['host'];

		if ( ! empty( $parsed_url['port'] ) ) {
			$url .= ':' . $parsed_url['port'];
		}

		if ( ! empty( $parsed_url['path'] ) ) {
			$url .= $parsed_url['path'];
		}

		if ( ! empty( $parsed_url['query'] ) ) {
			$url .= '?' . $parsed_url['query'];
		}
	}

	return $url;
}

常見問題

FAQs
檢視更多 >