[Resolved] header – primary navigation – search icon always on a new line

Home Forums Support [Resolved] header – primary navigation – search icon always on a new line

Home Forums Support header – primary navigation – search icon always on a new line

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2150963
    Stephen

    http://www.stephenlavender.site

    I’ve turned on navigation search in primary navigation layout options and the search icon is always on its own line in the navigation menu.
    I understand as the navigation menu re sizes it can use another line but the search icon is always on a new line by itself

    – Can I get the search icon on the same line as the rest of the menu?

    Thanks
    Stephen

    #2150983
    David
    Staff
    Customer Support

    Hi there,

    Try adding this PHP Snippet to your site:

    add_action( 'wp', function() {
        remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
    }, 500 );
    
    add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
        if ( 'enable' !== generate_get_option( 'nav_search' ) ) {
            return $nav;
        }
    
        if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
            $search_item = apply_filters(
                'generate_navigation_search_menu_item_output',
                sprintf(
                    '<li class="search-item menu-item-align-right"><a aria-label="%1$s" href="#">%2$s</a></li>',
                    esc_attr__( 'Open Search Bar', 'generatepress' ),
                    generate_get_svg_icon( 'search', true )
                )
            );
    
            return $nav . $search_item;
        }
    
        return $nav;
    }, 10, 2 );

    How to Add PHP: https://docs.generatepress.com/article/adding-php/

    #2150992
    Stephen

    great thanks, works perfectly as always.

    Now though I dont have a search icon on mobile screen sizes

    – can I get the search icon back on my mobile screen size header ?

    Thanks
    Stephen

    #2151004
    David
    Staff
    Customer Support

    Remove this part of the snippet:

    add_action( 'wp', function() {
        remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
    }, 500 );

    It should now show 2x on Desktop, if it does let us know and ill provide the CSS to remove the duplicate

    #2151012
    Stephen

    Hi, yes thats right there is 2 search icons now, 1 inline with the menu and one on a new line in desktop

    #2151018
    David
    Staff
    Customer Support

    Add this CSS:

    @media(min-width: 850px) {
        .main-navigation .menu-bar-item.search-item {
            display: none;
        }
    }
    #2151028
    Stephen

    thats great thanks

    In the mobile header the search icon is grey and a bit small.

    – Can I make the search icon white and make it bigger for mobile screen size ?

    Thanks
    Stephen

    #2151046
    David
    Staff
    Customer Support

    Try this:

    #mobile-header .menu-bar-items a {
        color: #fff;
        font-size: 20px;
    }
    #2151066
    Stephen

    thats perfect, thank you

    #2151079
    David
    Staff
    Customer Support

    You’re welcome

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