I use a menu on top of my wordpress which shows 3 links.

  1. Main page
  2. Custom Page
  3. Custom Page

Can I add a 4th link to my menu which is visible and accessible to admins only (without plugins)? This 4th page would also be a custom page I make. How would I go about setting this up, or does anyone have somewhere to start?

  • 3
    Saying without plugins is akin to saying without code. – Wyck Jun 18 '13 at 3:50
  • How is your menu output in your theme, is it a Navigation Menu, or wp_list_pages, or? – Milo Jun 18 '13 at 3:58
  • @Wyck Maybe I used bad wording, but basically I don't want to use someone elses code added as a plugin. I want to edit the php pages myself if that makes sense. The information is sensitive and I don't like blindly trusting plugins which I don't really know about. – Cully Jun 18 '13 at 5:55
  • @Milo I'm not sure what you mean. Here's what loads the menu on my header.php: echo theme_get_menu(array('source' => theme_get_option('theme_menu_source'), 'depth' => theme_get_option('theme_menu_depth'), 'menu' => 'primary-menu', 'class' => 'fmls-hmenu')); Does that answer your question? – Cully Jun 18 '13 at 5:57

You can show or hide something based on a user's role with the current_user_can() function. For the Administrator role you would check if current_user_can( 'administrator' ).

Here's a quick and dirty example of hiding a nav menu item by first checking if the title matches a particular page, and then checking if the current user is not an administrator, via the wp_nav_menu_objects filter. If both conditions are satisfied, the menu item is removed via php's unset.

function wpa_filter_nav_menu_objects( $items ){
    foreach( $items as $key => $item ){
        if( 'Private page' == $item->title && !current_user_can( 'administrator' ) ){
            unset( $items[$key] );
    return $items;
add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );
  • Please remember, the title of the page is case-sensitive. – gurung Mar 27 '14 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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