Site logo

Archived topic

Search on top navigation

5 replies · Started by Nicole on March 16, 2022

Viewing posts 1–6 of 6

Is it possible to add a search function to the top navigation (where the "home" link is) instead of or in addition to the second navigation?

Thanks.
I tried the first option but it added a search box and I only wanted the search icon.
I then tried the second option. I added the code and activated the navigation search option but it removed the search icon from the second navigation and didn't add it to the first navigation.

I see.

If that’s the case, for the first approach, you may try adding a new search plugin that has such a widget design, and add it as mentioned by David.

For the second approach, you’ll need to have a secondary menu set in Appearance > Customize > Menus: https://share.getcloudapp.com/6quZDd9W

Also see: https://share.getcloudapp.com/ApuJy76p

However, it seems that you’re “secondary menu” is a Top Bar instead. With your current structure, you can try creating a portable hook and place it in the top bar.

Portable hook code:

function your_shortcode($atts, $content = null) {
      ob_start();
      do_action('hook_name');
      return ob_get_clean();
}
add_shortcode(‘portable_hook’, 'your_shortcode');

After adding this PHP, you may add shortcode to the Top Bar as such: https://share.getcloudapp.com/mXuY7knN

Then modify the code you’ve added from the code as such:

add_action( 'wp', function() {
    if ( 'enable' === generate_get_option( 'nav_search' ) ) {
        remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
        add_action( 'hook_name', 'generate_do_navigation_search_button' );

        remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
        add_action( 'hook_name', 'generate_navigation_search' );
    }
}, 20 );

Hope this helps! :)

Thanks!

You’re welcome Nicole! Glad to be of assistance! Feel free to reach out anytime if you’ll need assistance with anything else. :)

This archived topic is closed to new replies.