Admin only menu/page

Is it possible to show a menu item If only admin is logged in)

For any other user the menu item does not appear.

Read More

For example: if there are a few pages that have shortcodes or other functionality exampled to show how to build toggles etc, but only want the admin to be able to see them. These pages generally come with pre-built themes and show the admin how to build pages within the site.

By hiding the menu items, a series of pages can be “hidden” from a user but allow the admin to see them to be able to build pages, without having to remove them entirely from the site

😛 make sense?

Related posts

1 comment

  1. Yes, it is possible.

    You could use wp_nav_menu_objects or wp_nav_menu_items hooks to add your filter function.

    function my_hide_menu_items($objects) {
        if ( is_admin() ) return $objects;
    
        foreach ( $objects as $k=>$object ) {
            if ( YOUR CONDITION ) {  // if $object shouldn't be displayed
                unset($objects[$k]);
            }
        }
        return $objects;
    }
    add_filter('wp_nav_menu_objects', 'my_hide_menu_items', 10, 2);
    

    You can also use this plugin: http://wordpress.org/plugins/menu-items-visibility-control/ (I haven’t tested it, so I’m not sure if it really works).

Comments are closed.