钩子文档

{$permastructname}_rewrite_rules

💡 云策文档标注

概述

此文档介绍 {$permastructname}_rewrite_rules 过滤器钩子,用于修改特定 permastruct 的重写规则。它允许开发者自定义如自定义文章类型或分类法的重写规则。

关键要点

  • 钩子名称中的 $permastructname 是动态部分,指代注册的 permastruct 名称,例如 category_rewrite_rules、post_format_rewrite_rules、post_tag_rewrite_rules。
  • 参数 $rules 是一个字符串数组,包含为当前 permastruct 生成的重写规则,以正则表达式模式为键。
  • 此过滤器钩子可用于修改自定义 permastructs,包括内置或自定义的文章类型和分类法。
  • 源代码示例:$rules = apply_filters( "{$permastructname}_rewrite_rules", $rules );
  • 相关函数:WP_Rewrite::rewrite_rules() 用于从固定链接结构构建重写匹配和查询。
  • 版本历史:自 WordPress 3.1.0 引入。

📄 原文内容

Filters rewrite rules used for individual permastructs.

Description

The dynamic portion of the hook name, $permastructname, refers to the name of the registered permastruct.

Possible hook names include:

  • category_rewrite_rules
  • post_format_rewrite_rules
  • post_tag_rewrite_rules

Parameters

$rulesstring[]
Array of rewrite rules generated for the current permastruct, keyed by their regex pattern.

More Information

This filter hook allows you to modify various custom permastructs, such as those generated for custom post types or taxonomies (both built-in or custom).

Source

$rules = apply_filters( "{$permastructname}_rewrite_rules", $rules );

Changelog

Version Description
3.1.0 Introduced.