Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

Comments

  1. Bill Gram-Reefer says:

    works but (lol) for my situation I want to add “Search” to the primary header as if it were just another item that got checked in

    appearance/menus/add-to-menu

    Everything I’ve seen creates a whole new…what is it a div…(?)

    that adds a whole new row to the header instead of p[lacing the form in the same row as ABOUT, etc. items in the primary navigation edit window.

    AND take the css assigned to the navigation bar.

  2. Josalone Wordsworth says:

    I really liked the post, so useful. However lets say I want to add a login and logout link in the footer with and if condition

  3. Hugo Callens says:

    Related question: how to add a menu item based on a specific user role?
    Say I have a custom user role called “Student” and I would like to add an item to the menu only when the user has the role of “Student”?

  4. Monilal says:

    Its works but current menu item not select

  5. james says:

    is there a way to add it on certain submenu instead of top ul?

  6. Gerrit says:

    Thank you for the How To!

    To be honest I don’t understand how you call the function.

    Especially I am missing a mention what arguments you call the functions with i.e. what wp variables to hand over as $items and $args.

    Could you please detail for a wp-beginner?

    Thank you,

    Gerrit

  7. samuel says:

    hey how if i want to add it to sub menu ?

  8. lokitoki says:

    hm any ideas how i could add html tags to just one wordpress menu item.

    from this:

    Contact

    to this:

    Contact

    it should be only for one menu item. not to all

  9. lokitoki says:

    hm any ideas how i could edit the tag for one wordpress menu item.

    from this:

    Contact

    to this:

    Contact

    it should be only for one menu item. not to all

  10. gonzela2006 says:

    Hello,
    How can I add the following classes active and current-menu-item and the id menu-item-id ?

  11. Lại Đình Cường says:

    How about add new custom menu to specific position?

  12. Guillermo says:

    I want put a little image beside left to the menu home, how can put it?
    please help me

  13. Pierre Laflamme says:

    In your examples, you add items to the primary menu (theme_location == ‘primary’).

    How would I add an item in a specific menu in widget area? Where do I get the theme_location?

    • WPBeginner Support says:

      theme locations are usually defined by your theme, check your theme’s functions.php file or the template where a menu is displayed.

    • Brad Trivers says:

      If you want to target a specific menu (not a theme location) then use $args->menu->slug == ‘the_menu_slug’ instead of $args->theme_location == ‘primary’.

  14. razvan says:

    Hi! I used your tutorial to put a picture as a logo overlapping the menu bar. All is fine but this specific menu has a hover option that makes the color white… So when i hover the mouse on the logo, it also hovers the link which kind of ruins the aspect of the page.

    This is my code:

    if( $args->theme_location == ‘primary’ )
    return ““.$items;

    How can I hide the a href on the page and just display the image with link?

    Thanks in advance

  15. Kathy says:

    Hi, I think your code is close to what I’m looking for, but I’m trying to figure out how i can customize it to do what I’m trying to do!

    What I am trying to do is create a menu item with dropdown list of authors? any idea how i can accomplish that?

    Thanks so much!

  16. sachi says:

    awesome i was searching these codes

  17. Brad says:

    Thanks this was very helpfull,

    However, out of curiosity, I can’t find this valuable filter hook: “‘wp_nav_menu_items” , I mean where in WP core files is this being called ??

    Thanks much !!

    • WPBeginner Support says:

      It is located in wp-includes/nav-menu.php, however it is not recommended to modify core files. It is a filter and you can call it in your theme’s functions.php file or a site specific plugin.

  18. Lavinia says:

    This isn’t work for me :(

  19. Andor Nagy says:

    How can I place it in front of the first menu item? Otherwise great tutorial!

    Regards,
    Andor Nagy

    • Editorial Staff says:

      Use the return example of the search bar and move the items towards the end?

    • Cameron Jones says:

      add_filter( ‘wp_nav_menu_items’, ‘your_custom_menu_item’, 10, 2 );

      function your_custom_menu_item ( $items, $args ) {

      $custom = ‘Show whatever’;

      $items = $custom.$items;

      return $items;

      }

  20. Murugu says:

    Pardon my ignorance but which php file would I be editing?

    • Editorial Staff says:

      This would go in your functions.php file.

      • Murugu says:

        I added the following to my theme’s functions.php but the search box doesn’t show up like I would expect. Any suggestions?

        add_filter(‘wp_nav_menu_items’,’add_search_box_to_menu’, 10, 2);
        function add_search_box_to_menu( $items, $args ) {
        if( $args->theme_location == ‘header_extras_inner’ )
        return $items.””;

        return $items;
        }

  21. Elliott Wall says:

    Sorry to be coming into this discussion so late

    I’ve tried the search form part and it works great— thank you! I’m having problems styling it though, for some reason. No matter what I do the placeholder text in the field is gray. I’ve looked at the cascading of the styles and messed with so many things— I can change the background color for example, but no luck in making the text black, so the design continuity of the menu is somewhat compromised. My site is http://elliottwall.com if you care to have a look. Cheers

    • Editorial Staff says:

      For placeholder text, you have to do something like this:

      ::-webkit-input-placeholder {
         color: red;
      }
      
      :-moz-placeholder { /* Firefox 18- */
         color: red;  
      }
      
      ::-moz-placeholder {  /* Firefox 19+ */
         color: red;  
      }
      
      :-ms-input-placeholder {  
         color: red;  
      }
      
  22. Sam says:

    Can we add custom link before the first item instead of at the end?

  23. SAcha says:

    Hi,

    very interesting!
    I added a custom link, but is it possible to add it in a certain position inside the menu? Like “after the first menu item”.

    Thanks

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 comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.