user_trailingslashit

函式
user_trailingslashit ( $string, $type_of_url = '' )
引數
  • (string) $string URL with or without a trailing slash.
    Required:
  • (string) $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) for use in the filter. Default empty string.
    Required:
    Default: (empty)
返回值
  • (string) The URL with the trailing slash appended or stripped.
定義位置
相關方法
trailingslashituntrailingslashitset_transientwp_user_settingsget_user_details
引入
2.2.0
棄用
-

user_trailingslashit: 如果一個URL還沒有尾部斜線的話,這個函式會給它加上一個尾部斜線。

如果網站設定了新增尾部斜槓的功能,則檢索一個尾部斜槓字串。

如果固定連結結構有尾部斜線,則有條件地新增尾部斜線,如果沒有則刪除尾部斜線。該字串會通過{@see ‘user_trailingslashit’}過濾器。如果網站沒有設定尾部斜槓,將從字串中刪除尾部斜槓。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function user_trailingslashit( $string, $type_of_url = '' ) {
global $wp_rewrite;
if ( $wp_rewrite->use_trailing_slashes ) {
$string = trailingslashit( $string );
} else {
$string = untrailingslashit( $string );
}
/**
* Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
*
* @since 2.2.0
*
* @param string $string URL with or without a trailing slash.
* @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
* 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
* 'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
*/
return apply_filters( 'user_trailingslashit', $string, $type_of_url );
}
function user_trailingslashit( $string, $type_of_url = '' ) { global $wp_rewrite; if ( $wp_rewrite->use_trailing_slashes ) { $string = trailingslashit( $string ); } else { $string = untrailingslashit( $string ); } /** * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. * * @since 2.2.0 * * @param string $string URL with or without a trailing slash. * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', * 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', * 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. */ return apply_filters( 'user_trailingslashit', $string, $type_of_url ); }
function user_trailingslashit( $string, $type_of_url = '' ) {
	global $wp_rewrite;
	if ( $wp_rewrite->use_trailing_slashes ) {
		$string = trailingslashit( $string );
	} else {
		$string = untrailingslashit( $string );
	}

	/**
	 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
	 *
	 * @since 2.2.0
	 *
	 * @param string $string      URL with or without a trailing slash.
	 * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback',
	 *                            'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed',
	 *                            'category', 'page', 'year', 'month', 'day', 'post_type_archive'.
	 */
	return apply_filters( 'user_trailingslashit', $string, $type_of_url );
}

常見問題

FAQs
檢視更多 >