[Resolved] Move search function to secondary menu position

Home Forums Support Move search function to secondary menu position

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #332805
    Rogier

    Hi Tom,

    I’m trying to move the search function to the Secondary Navigation position instead of the Primary Navigation position. Is there a function for this? Notice: The before header hook is not deep enough, because I want it to be part of the menu list.

    Or when not possible, the second best solution: How can I load the following code inside the secondary menu list, so the searchform.php can be overwritten in the Child theme with a custom search mark-up?

    <li><?php get_search_form(); ?></li>

    Thanks in advance!

    Kind regards,

    Rogier

    GeneratePress 1.3.48
    #332944
    Leo
    Staff
    Customer Support

    Hi there,

    The easiest way would be to switch the primary and secondary menu since they both have the same options.

    So make the menu you want the search icon primary.

    Let me know if this makes sense 🙂

    #333077
    Rogier

    Hi Leo,

    Switching the location of the primary and secondary is a clever thought, but this won’t give the desired effect, just an mainmenu in the topbar and vice versa.

    I’m guessing you don’t understand what I mean with my questions?

    Kind regards,

    Rogier

    #333090
    Leo
    Staff
    Customer Support

    Hmm both primary and secondary navigation should have the same settings. Maybe Tom explains better in this post: https://generatepress.com/forums/topic/move-navigation-search/

    Let me know if that helps.

    #333155
    Rogier

    For anyone else searching for the solution of my earlier question, adding this to functions.php this will do the trick:

    add_filter('wp_nav_menu_items','add_search_box', 10, 2);
    function add_search_box($items, $args) {
    	
    	if( $args->theme_location == 'secondary')  {
            ob_start();
            get_search_form();
            $searchform = ob_get_contents();
            ob_end_clean();
            
            $items .= '<li class="search-item">' . $searchform . '</li>';        
        }
    
        return $items;
    }

    Kind regards,

    Rogier

    #333187
    Tom
    Lead Developer
    Lead Developer

    Nice! Thanks for sharing that solution! 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.