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’}过滤器。如果网站没有设置尾部斜杠,将从字符串中删除尾部斜杠。

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
查看更多 >