Add A Custom Primary Nav Extras within Genesis

Add A Custom Primary Nav Extras within Genesis

This morning while browsing the Genesis support forums, I came across a question on how to “Aligning last menu item to the right“.  I knew Genesis had the Primary Navigation Extra option to add an additional item to your primary menu through the Genesis options menu.

Genesis Primary Navigation Extras
Genesis Primary Navigation Extras

I began digging through the Genesis source code and found the Genesis ‘wp_nav_menu_items’ filter.  By creating a custom callback for the filter, I was able to create my own custom Primary Navigation Extra.

Custom Primary Nav Exra
Custom Primary Nav Exra

This code can be copied into your Genesis child theme’s functions.php file.

Published by

rfmeier

Product developer at WPEngine and runner from Hampshire, Illinois. I work with php a lot; Spending most of my time digging into source code to see how it all works. You can find me on Twitter @rfmeier.

28 thoughts on “Add A Custom Primary Nav Extras within Genesis”

  1. Hi Ryan – useful bit of coding

    Once you create the “custom Primary Navigation Extra” does it appear in the drop down menu or do you just change the wording within the code?

    $menu .= sprintf( ‘%s’, __( ‘Your custom code’ ) );

    1. Keith,

      It does not appear within the drop-down menu. The options are hard-coded within the Genesis source code and there was not a way to extend them. So yes. You will have to supply the content.

      Thanks for looking.

  2. Thanks for making this Ryan!

    Would you also happen to know how to remove the left padding on the first menu item?

    On the demo page, http://genesisframework.com, the first and last menu items are labeled with .first and .last, so that they align properly.

    1. Mathias,

      You are welcome. As for your question, I would ask on the Genesis Support Forums. You would probably get more support there.

  3. Does this still work with the current update of Genesis?

    Do we put it under

    require_once( dirname( __FILE__ ) . ‘/lib/init.php’ ); in the functions.php?

  4. So, what if I wanted to add the get_search_form() hook? I’m no PHP wizard…so this is probably a completely stupid question…but I thought I’d ask any way.

    1. Okay…oops…forgot the proper tags…

      Here’s the code done properly.

      $menu .= sprintf( '%s',get_search_form() );

    2. Okay…your comment settings are stripping the code. of the li section(s)…oh well. I worked it out, regardless.

  5. Been looking all over for this very thing! Thanks! I just needed to put a shortcode instead of the text and did so by using doshortcode instead:

    // append your custom code
    $menu .= sprintf( '%s', do_shortcode( '[ajax_autosuggest_form]' ) );

    1. I also wanted to add a shortcode object to the menu. But how do I get it to justify right? I tried:

      // append your custom code
      $menu .= sprintf( ‘%s’, do_shortcode( ‘[feather_follow size=”22″]’ ) );

      It moves it right but also adds spaces to the object and menu. Any ideas how to fix this?

    2. Part of the code above is missing. It should be:

      // append your custom code
      $menu .= sprintf( ‘%s’, do_shortcode( ‘[feather_follow size=”22″]’ ) );

    3. Yes, it’s lifeandlemurs.com. And by the way, the above is still missing part of the code. It cuts part of it out when posted.

      When I follow your code it will justify right just fine. It’s adding the shortcode object that seems to cause problems.

      Thank you!

  6. Hey Ryan,

    Thanks for posting this, I really appreciate it. Is it possible to use this technique to float a logo to the left of the nav menu. When I try changing the class to “left” instead of “right” it drops the logo down to the next line and creates a bullet. Here is a mock up of what I am trying to achieve: http://imgur.com/BkCfZsF

    Thanks for your help!

    -Dave

Leave a Reply

Your email address will not be published. Required fields are marked *