Remove Categories From WordPress
Recently I’ve developed a WordPress site and I’ve added a custom post page to insert, edit and delete some specific types of post easily without going to WordPress native post page for non-admin users. In that case I had to remove those categories from WordPress native post page only for those who were able to use my custom post page. To do this I’ve searched the Google and found a solution but I had to made some changes to fit my needs. The following code snippet will remove two categories from WordPress Post page. To do this, just add the code snippet to your functions.php file.
function remove_categories($categories) { // If we are in the new/edit post page and not an admin, then remove categories "events" and "testimonial" $onPostPage = (strpos($_SERVER['PHP_SELF'], 'post.php') || strpos($_SERVER['PHP_SELF'], 'post-new.php')); if (is_admin() && $onPostPage && !current_user_can('level_10')) { $size = count($categories); for ($i = 0; $i < $size; $i++) { if ($categories[$i]->slug == 'events' || $categories[$i]->slug == 'testimonial') { unset($categories[$i]); } } } return $categories; } // Add the filter add_filter('get_terms', 'remove_categories');