WordPress 技巧:如何移除自定义文章类型菜单下自定义分类子菜单

假设我们创建了一个 product 的自定义文章类型,然后又创建了一个 product_category 自定义分类,并且关联上了 product 这个自定义文章类型,这样在后台 product 自定义文章类型菜单下就有 product_category 的子菜单。

这个子菜单的链接是:

edit-tags.?taxonomy=product_category&post_type=product

由于某种原因,我们要移除这个子菜单,根据 remove_submenu_page 函数的的要求,就写了下面的代码来移除:

remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_category&post_type=product' );

但是并不生效,这是因为 Press/ target=_blank class=infotextkey>WordPress 生成子菜单的时候,如果子菜单的链接有 & 的时候会被转换成 &  实体,所以正确的移除方法是:

remove_submenu_page( 'edit.php?post_type=product', 'edit-tags.php?taxonomy=product_category&post_type=product' );
胜象大百科