Answers:
register_taxonomy()
是工作的工具。从食典:
此功能添加或覆盖分类法。
一种选择是复制register_taxonomy()
$args
和修改它们。但是,这意味着将来对原始register_taxonomy()
代码的任何更改都将被覆盖。
因此,至少在这种情况下,最好获取原始参数,修改我想要更改的参数,然后重新注册分类法。此解决方案的灵感来自@Otto,它回答了有关自定义帖子类型的类似问题。
使用示例中的people
自定义帖子类型和people_category
分类法,可以做到这一点:
function wpse_modify_taxonomy() {
// get the arguments of the already-registered taxonomy
$people_category_args = get_taxonomy( 'people_category' ); // returns an object
// make changes to the args
// in this example there are three changes
// again, note that it's an object
$people_category_args->show_admin_column = true;
$people_category_args->rewrite['slug'] = 'people';
$people_category_args->rewrite['with_front'] = false;
// re-register the taxonomy
register_taxonomy( 'people_category', 'people', (array) $people_category_args );
}
// hook it up to 11 so that it overrides the original register_taxonomy function
add_action( 'init', 'wpse_modify_taxonomy', 11 );
注意,上面我将第三个register_taxonomy()
参数转换为期望的数组类型。由于可以处理或的register_taxonomy()
用途wp_parse_args()
,因此这并非绝对必要。这就是说,的都应该是作为一份根据食品法典委员会,所以这种感觉对我。object
array
register_taxonomy()
$args
array
'people_category'
原始分类法相同的标记(例如),以便将其覆盖。