X

How to Hide Posts and Pages in the WordPress Admin Panel

Snippets by IsItWP

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:

<?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.

If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).

Comments  Leave a Reply

  1. Selçuk Ahmet July 23, 2017 at 7:40 am

    hahaaa after 5 years still kicks wordpress ass

  2. GREAT SOLUTION!!! I SEARCHED A LOT TO FIND THIS !!! THANK’S!!!

  3. Cool! thanx 🙂

  4. Yes this would be a better solution thanks for posting.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!