registered_taxonomy_{$taxonomy}
云策文档标注
概述
registered_taxonomy_{$taxonomy} 是一个 WordPress 动态 Hook,在特定分类法注册完成后触发。它允许开发者在分类法注册后执行自定义操作,例如修改参数或添加功能。
关键要点
- 这是一个动态 Hook,名称中的 $taxonomy 部分替换为具体的分类法键(如 category 或 post_tag)。
- Hook 在 register_taxonomy() 函数中调用,传递分类法键、对象类型和参数数组。
- 可用于在分类法注册后执行自定义代码,例如日志记录或动态调整设置。
代码示例
/**
* Example of registered_taxonomy_{taxonomy} usage. In this case: customtax taxonomy
* @param string $taxonomy Taxonomy key. In this case: customtax
* @param array|string $object_type Name of the object type for the taxonomy object.
* @param array|string $args Optional args used in taxonomy registration.
*/
function wporg_registered_taxonomy_customtax( $taxonomy, $object_type, $args ) {
// Do something after customtax is registered as custom taxonomy
}
add_action( 'registered_taxonomy_customtax', 'wporg_registered_taxonomy_customtax', 10, 3 );
原文内容
Fires after a specific taxonomy is registered.
Description
The dynamic portion of the filter name, $taxonomy, refers to the taxonomy key.
Possible hook names include:
registered_taxonomy_categoryregistered_taxonomy_post_tag
Parameters
$taxonomystring-
Taxonomy slug.
$object_typearray|string-
Object type or array of object types.
$argsarray-
Array of taxonomy registration arguments.
Source
do_action( "registered_taxonomy_{$taxonomy}", $taxonomy, $object_type, (array) $taxonomy_object );
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |
Skip to note 2 content
Antonio Blanco Oliva
/**
* Example of registered_taxonomy_{taxonomy} usage. In this case: customtax taxonomy
* @param string $taxonomy Taxonomy key. In this case: customtax
* @param array|string $object_type Name of the object type for the taxonomy object.
* @param array|string $args Optional args used in taxonomy registration.
*/
function wporg_registered_taxonomy_customtax( $taxonomy, $object_type, $args ) {
// Do something after customtax is registered as custom taxonomy
}
add_action( ‘registered_taxonomy_customtax’, ‘wporg_registered_taxonomy_customtax’, 10, 3 );