X

Hide posts and pages within the admin from users

I have had a few projects that required me to create a page that is for template use only. I may need to add shortcode or something to the page. Now since I don't want my client to edit this page and possibly break things I hide the pages. Adding this snippet to the functions.php of your wordpress theme will allow you to add id's for each of the posts or pages you wish to hide.



Code Snippet:


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

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!