如何删除自定义帖子类型菜单中的类别?
1 个回答
- 投票数
这很快就被黑了.我不确定翻译是否会出现问题,但我会存在.
function remove_menu_from_cpt() {
global $submenu;
$post_type = 'book';
$tax_slug = 'post_tag';
if (isset($submenu['edit.php?post_type='.$post_type])) {
foreach ($submenu['edit.php?post_type='.$post_type] as $k => $sub) {
if (false !== strpos($sub[2],$tax_slug)) {
unset($submenu['edit.php?post_type='.$post_type][$k]);
}
}
}
}
add_action('admin_menu','remove_menu_from_cpt');
它使用了'book'帖子类型和帖子标签,因为这对我来说很方便测试,但是很明显需要进行哪些更改才能使其适合您的情况-我相信您需要:
$post_type = 'my_custom_post_type_name';
$tax_slug = 'category';
This was hacked together very quickly. I don't for sure if there will be problems with translation, but I be there would be.
function remove_menu_from_cpt() {
global $submenu;
$post_type = 'book';
$tax_slug = 'post_tag';
if (isset($submenu['edit.php?post_type='.$post_type])) {
foreach ($submenu['edit.php?post_type='.$post_type] as $k => $sub) {
if (false !== strpos($sub[2],$tax_slug)) {
unset($submenu['edit.php?post_type='.$post_type][$k]);
}
}
}
}
add_action('admin_menu','remove_menu_from_cpt');
It used the 'book' post type and post tags, because that was convenient for me to test, but it pretty obvious what needs to change to make this work for your case-- I believe you need:
$post_type = 'my_custom_post_type_name';
$tax_slug = 'category';
我正在创建自定义帖子类型,并添加了类别分类.这可以通过两种方式完成:
在这两种情况下,我的自定义帖子菜单的左侧管理菜单中都会显示一个附加的子菜单项.
类别已经显示在
Post
菜单下,因此我不需要再次显示.有什么预防方法吗?