Home / functions.php / Hide posts and pages within the admin from users
  • How to Hide posts and pages within the admin from users

    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.

    ( click code to copy )

    wordpress snippet : PHP

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

    ( WordPress codex functions, hooks, in this snippet. )

    admin_head, get_currentuserinfo, add_action,
  • Yes this would be a better solution thanks for posting.

  • Cool! thanx :)

  • stephane

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