This is a great snippet if you need to customize your WordPress Admin just a little bit. For example, if you aren't interested in having WordPress' default taxonomies (categories and tags) on your blog posts, and, therefore, don't want those unused options cluttering up your backend.
First, remove the default taxonomies categories, tags from the Admin menu. Now, because this only removes the menu item if you visit the URL edit-tags.php?taxonomy=post_tag
, you’ll still have access to tags and categories. Next, check the $pagenow
to see if you're on edit-tags.php
. Then, check taxonomy=post_tag
to see if it’s post_tag or category and return with an error. Just add this snippet to the functions.php of your WordPress theme and you’re all set.
function wpsnipp_remove_default_taxonomies(){ global $pagenow; register_taxonomy( 'post_tag', array() ); register_taxonomy( 'category', array() ); $tax = array('post_tag','category'); if($pagenow == 'edit-tags.php' && in_array($_GET['taxonomy'],$tax) ){ wp_die('Invalid taxonomy'); } } add_action('init', 'wpsnipp_remove_default_taxonomies');
Comments Leave a Reply