How to Hide Posts and Pages in the WordPress Admin Panel

Do you want to hide posts and pages in Your WordPress admin panel? By hiding some posts and pages in your admin panel, you can restrict your clients from editing them. This comes in handy if you want to have some pages on your site ONLY for your templates in which you need to add shortcodes or something else that no one should edit.

This snippet allows you to specify the IDs of the posts and pages that you want to hide in WordPress dashboard.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
add_action('admin_head', 'hide_posts_pages');
  
function hide_posts_pages() {
    global $current_user;
    get_currentuserinfo();
    If($current_user->user_login != 'admin') {
        ?>
        <style>
           #post-10, #post-11, #post-12, #post-13, #post-14{
                display:none;
           }
        </style>
        <?php
    }
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

 

 

How to hide certain categories in wordpress dashboard?

I have two categories which I don’t want to show to my site’s admin, I want them to be added automatically every time a new post is created or updated. I have the code for it. But now i also want to hide those two categories.

This is not for front-end. This is for WordPress dashboard. I don’t want that admin will see these two categories at all. But if we hide those still I will be to assign two categories into posts.

 

 

/*
 * Hide Specified Categories (by ID) from Editors
 */

add_action( 'admin_init', 'wpse_55202_do_terms_exclusion' );

function wpse_55202_do_terms_exclusion() {
    if( current_user_can('editor') )
        add_filter( 'list_terms_exclusions', 'wpse_55202_list_terms_exclusions', 10, 2 );
}

function wpse_55202_list_terms_exclusions($exclusions,$args) {
    return $exclusions . " AND ( t.term_id <> 1 )  AND ( t.term_id <> 17 )"; 
}