Hi, one of my recent tasks was to somehow hide the taxonomy “Categories” and “Tags” under the default “Posts” in WordPress. I was doing quite a bit customization over WordPress Custom Post Type and Custom Taxonomy lately with WordPress projects; thus, it is also a good idea to further customize the default “Posts” a bit to make a more user friendly back-end in WordPress.
The reason to hide Categories and Tags is that these taxonomy is barely edited and can be locked down for site maintenance purpose.
We know that to customize the custom taxonomy, we need to use the WordPress function register_taxonomy. Check this function in WordPress to take a look the parameters and specify what is needed and what is not in WP Admin Panel. In order to hide the access to manage, edit and delete taxonomy, we can use one of the function option called “capabilities” and specify correct option value to do so.
The following code shows how (check comments):
register_taxonomy('project-tag',array('projects'),array( 'hierarchical' => true, 'labels' => $project_tag_labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => 'project-tag' ), 'capabilities' => array (// by default admin: manage-options; or by editor: edit_posts 'manage_terms' => 'manage-options', // means administrator 'edit_terms' => 'manage-options', 'delete_terms' => 'manage-options', 'assign_terms' => 'edit_posts' // means administrator', 'editor', 'author', 'contributor' ) ));
In above code, ‘manage_terms’, ‘edit_terms’ and ‘delete_terms’ are accessible by Admin only. And ‘assign_terms’ can be accessed by other roles of users.
The above code is to handle the custom taxonomy. In order to hide the default “Categories” and “Tags” under “Posts”, we can do the same thing to achieve that.
All we need to do is to locate where categories and tags are defined. In this case, they are under “taxonomy.php” in wp-include.
By default, taxonomy “Categories” is defined as the following:
register_taxonomy( 'category', 'post', array( 'hierarchical' => true, 'query_var' => 'category_name', 'rewrite' => $rewrite['category'], 'public' => true, 'show_ui' => true, '_builtin' => true, ) );
Based on the above coding potion of “capabilities”, all we need to do is to include “capabilities” with proper option values to successfully hide the accessibility of “Categories” and “Tags”.
Hope this little article helps you with your daily website development.