Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Created November 27, 2010 06:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeschinkel/717635 to your computer and use it in GitHub Desktop.
Save mikeschinkel/717635 to your computer and use it in GitHub Desktop.
Hide a Taxonomy in the WordPress Admin Menu
<?php
/*
See http://lists.automattic.com/pipermail/wp-hackers/2010-November/036174.html
Also: http://mikeschinkel.com/websnaps/skitched-20101127-012515.png
Author: Mike Schinkel
*/
add_action('admin_menu','yoursite_admin_menu');
function yoursite_admin_menu() {
global $submenu;
// This needs to be set to the URL for the admin menu section (aka "Menu Page")
$menu_page = 'edit.php';
// This needs to be set to the URL for the admin menu option to remove (aka "Submenu Page")
$taxonomy_admin_page = 'edit-tags.php?taxonomy=test_taxonomy';
// This removes the menu option but doesn't disable the taxonomy
foreach($submenu[$menu_page] as $index => $submenu_item) {
if ($submenu_item[2]==$taxonomy_admin_page) {
unset($submenu[$menu_page][$index]);
}
}
}
add_action('init','yoursite_init');
function yoursite_init() {
// This is just here to have an example to test with.
register_taxonomy('test_taxonomy', 'post', array(
'label' => 'Test Taxonomy',
'query_var' => 'test_taxonomy',
'rewrite' => array('slug' => 'test'),
'public' => true,
'show_ui' => true,
) );
}
@ZaheerAbbasAghani
Copy link

ZaheerAbbasAghani commented Dec 29, 2021

The below code worked for me Instead of the above.

add_action( 'init', 'unregister_tags' );
function unregister_tags() {
unregister_taxonomy_for_object_type( 'taxonomy_name', 'post_type' );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment