钩子文档

user_trailingslashit

💡 云策文档标注

概述

user_trailingslashit 是一个 WordPress 过滤器,用于根据站点设置调整 URL 的尾部斜杠。它允许开发者基于 URL 类型动态添加或移除斜杠。

关键要点

  • 过滤器名称:user_trailingslashit,用于过滤 URL 字符串的尾部斜杠。
  • 参数:$url(带或不带尾部斜杠的 URL)和 $type_of_url(URL 类型,如 'single'、'category' 等)。
  • 应用场景:在 WordPress 链接生成中,根据站点配置自动处理斜杠,确保 URL 一致性。

代码示例

return apply_filters( 'user_trailingslashit', $url, $type_of_url );

注意事项

  • 引入版本:WordPress 2.2.0,自该版本起可用。
  • 相关函数:user_trailingslashit(),位于 wp-includes/link-template.php,用于检索带尾部斜杠的字符串。

📄 原文内容

Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.

Parameters

$urlstring
URL with or without a trailing slash.
$type_of_urlstring
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'.

Source

return apply_filters( 'user_trailingslashit', $url, $type_of_url );

Changelog

Version Description
2.2.0 Introduced.