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
  • Pierre Laflamme

    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?

    • http://www.wpbeginner.com/ WPBeginner Support

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

  • razvan

    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

  • Kathy

    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!

  • sachi

    awesome i was searching these codes

  • Brad

    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 !!

    • http://www.wpbeginner.com/ WPBeginner Support

      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.

  • Lavinia

    This isn’t work for me :(

  • Andor Nagy

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

    Regards,
    Andor Nagy

    • http://www.wpbeginner.com Editorial Staff

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

  • Murugu

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

    • http://www.wpbeginner.com Editorial Staff

      This would go in your functions.php file.

      • Murugu

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

  • Elliott Wall

    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

    • http://www.wpbeginner.com Editorial Staff

      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;  
      }
      
      • Elliott Wall

        This worked perfectly— thank you again!

  • Sam

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

    • xafar Ali

      Yes , just concatenate first instead of last.

      $items = “MENU ITEM ” . $items;

  • SAcha

    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

    • http://www.wpbeginner.com Editorial Staff

      Not sure if that is possible.