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).
Ignore my last request, I have sorted it!
This is a really good snippet, just what I was looking for but it is hiding the pages from all users including me (admin), how can I hide from a selected set of user admins that I have created using User Role Editor. Thanks in advance!
SCHALK thank you for help, can you post the function with one post and 1 page to see how will be the final cone?
Thanks
I apologize, I’m not sure if I understand the question.
Hi,
Is it possible to first add a class to each page, so that i can rather hide the injected class?
the same way i can assign the page slug as a class to a page with the code below.
The reason is, i wat ti make it easier to programatically hide pages if there are an options page present.
So instead of #post-10 it will be .post-about or .post-contact
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . ‘-‘ . $post->post_name;
}
return $classes;
}
add_filter( ‘body_class’, ‘add_slug_body_class’ );
Thank you.
Schalk
hahaaa after 5 years still kicks wordpress ass
GREAT SOLUTION!!! I SEARCHED A LOT TO FIND THIS !!! THANK’S!!!
Cool! thanx 🙂
Yes this would be a better solution thanks for posting.