Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

For any other user the menu item does not appear.

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

:P make sense?

share|improve this question
add comment

1 Answer

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

share|improve this answer
    
Im so glad you answered but I have no clue as what to do to implement this :( Does this part: 10, 2) point to a menu item? or the CONDITION do I point it at a page? - sorry if I sound like a doofus.......! –  idaryl Jul 12 '13 at 20:57
    
No, 10 is priority and 2 is number of parameters (codex.wordpress.org/Function_Reference/add_filter). The only thing you have to modify is to replace YOUR CONDITION with your real condition. I can't do this for you, because I have no idea how to tell if given menu item should be hidden or not (it's your call). –  Krzysiek Dróżdż Jul 12 '13 at 21:02
    
I just installed that plugin and it seems to work just fine - pretty straight forward... put all the pages under a menu item, added it to the end of my regular menu and set it for the admin. It now only shows when the admin is logged in, just what I needed - thank you! –  idaryl Jul 12 '13 at 21:07
    
No problem. Just mark the answer as correct if it solved your problem ;) –  Krzysiek Dróżdż Jul 12 '13 at 21:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.