钩子文档

post_link_category

💡 云策文档标注

概述

post_link_category 是一个 WordPress 过滤器,用于控制 %category% 固定链接令牌中使用的分类。它允许开发者自定义或修改在生成文章链接时选择哪个分类。

关键要点

  • 过滤器名称:post_link_category
  • 用途:过滤用于 %category% 固定链接令牌的分类
  • 参数:$cat(WP_Term 对象,当前使用的分类)、$cats(数组,文章关联的所有分类)、$post(WP_Post 对象,当前文章)
  • 返回值:应返回一个 WP_Term 对象作为最终使用的分类
  • 引入版本:WordPress 3.5.0

代码示例

$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );

📄 原文内容

Filters the category that gets used in the %category% permalink token.

Parameters

$catWP_Term
The category to use in the permalink.
$catsarray
Array of all categories (WP_Term objects) associated with the post.
$postWP_Post
The post in question.

Source

$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );

Changelog

Version Description
3.5.0 Introduced.