Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
user_trailingslashit() - 如果站点设置为添加尾部斜杠,则检索尾部斜杠字符串 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / user_trailingslashit()

user_trailingslashit( string $string, string $type_of_url = '' )

如果站点设置为添加尾部斜杠,则检索尾部斜杠字符串


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "c1a818a38c2857eb318d2766bd35f8b7" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

usermore...


描述

如果固定链接结构具有尾部斜杠,则有条件地添加尾部斜杠,如果没有,则删除尾部斜杠。字符串通过‘user_trailingslashit’过滤器。如果站点未设置尾随斜杠,则将从字符串中删除尾随斜杠。


参数

$string

(string)(必填) 包含或不包含尾部斜杠的URL。

$type_of_url

(string)(可选) 被认为在过滤器中使用的URL类型(single、category等)。

默认值: ''


返回

(string) 附加或删除尾部斜杠的URL。



源码

查看源码 官方文档


更新日志

版本描述
2.2.0开始引入

使用示例

  • 示例1

    您可以从wordpress url中删除category,参见下面的示例。

    function wpdocs_remove_category( $string, $type ) {
    	if ( 'single' !== $type && 'category' === $type && false !== strpos( $string, 'category' ) ) {
    		$url_without_category = str_replace( '/category/', '/', $string );
    		return trailingslashit( $url_without_category );
    	}      
    	return $string;
    }    
    add_filter( 'user_trailingslashit', 'wpdocs_remove_category', 100, 2 );