• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Code doesn't work for adding search to nav bar

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Code doesn't work for adding search to nav bar

This topic is: resolved

Tagged: search box

  • This topic has 5 replies, 3 voices, and was last updated 9 years, 5 months ago by molly.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • February 8, 2017 at 11:47 am #200787
    molly
    Member

    On genesis 2.4.2 I added this code and still no option for adding search to the Nav bar. a) why do they keep changing this? b) how can I get a search box on my nav bar??

    Add Nav Extras

    Thanks

    http://101things.com/hhdev/
    February 8, 2017 at 1:59 pm #200794
    Victor Font
    Moderator

    Your nav bar is the secondary menu. The code in the snippet attaches to the primary nav bar. Change the word primary to secondary in the snippet.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 8, 2017 at 2:00 pm #200795
    molly
    Member

    I did that. Still doesn't work.

    February 9, 2017 at 2:30 am #200821
    Brad Dalton
    Participant

    Using FTP and a code editor, add the folowing code to your functions file

    add_filter( 'wp_nav_menu_items', 'theme_menu_extras', 10, 2 );
    function theme_menu_extras( $menu, $args ) {
    
    	if ( 'secondary' !== $args->theme_location )
    		return $menu;
    
    	ob_start();
    	get_search_form();
    	$search = ob_get_clean();
    	$menu  .= '<li class="right search">' . $search . '';
    
    	return $menu;
    
    }
    

    Tutorials for StudioPress Themes.

    February 9, 2017 at 5:24 am #200835
    Brad Dalton
    Participant

    The code breaks when embedded so try the following code on Github.

    Try here


    Tutorials for StudioPress Themes.

    February 9, 2017 at 5:39 pm #200877
    molly
    Member

    That worked. Thanks much!

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble