[Resolved] Double search icon on main and secondary navigation bars

Home Forums Support [Resolved] Double search icon on main and secondary navigation bars

Home Forums Support Double search icon on main and secondary navigation bars

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1641288
    Alex

    I found the following code to display search icon on secondary navigation bar. Unfortunately, when switching to flexbox, which is my current mode, the icon shows up on both main and secondary bars. Could you please help to remove it from the main bar?

    /*Search icon in secondary menu*/
    add_action( 'after_setup_theme', function() {
    	remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
    	remove_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' );
    	
    	add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' );
    	add_action( 'generate_inside_secondary_navigation', 'generate_mobile_menu_search_icon' );
    	
    	remove_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 );
    } );
    
    add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
    	$generate_settings = wp_parse_args(
    		get_option( 'generate_settings', array() ),
    		generate_get_defaults()
    	);
    
    	if ( 'enable' !== $generate_settings['nav_search'] ) {
    		return $nav;
    	}
    	
    	if ( 'secondary' === $args->theme_location ) {
    		$icon = generate_get_svg_icon( 'search', true );
    		return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#">' . $icon . '<span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '</span></a></li>';
    	}
    
    	return $nav;
    }, 10, 2 );
    
    #1641900
    Tom
    Lead Developer
    Lead Developer
    #1642032
    Alex

    Hi Tom! Yes, it works perfectly. But when the icon is clicked the search bar appears behind the main navigation bar and I can see only the very top of the input text.

    #1642304
    Leo
    Staff
    Customer Support

    Hi there,

    Any chance you can link us to the site in question?

    You can use the private information field.

    Let me know πŸ™‚

    #1642464
    Alex

    Yes, Leo.

    #1642870
    David
    Staff
    Customer Support

    Hi there,

    this CSS to stop the duplicate form from appearing:

    #mobile-header .navigation-search.nav-search-active {
      display: none;
    }

    Then CSS to moke sure the form is in front of the header:

    .navigation-search.nav-search-active {
      z-index: 10000;
    }

    Then you need to edit your CSS that is increasing the search input font size ie. this:

    .navigation-search input[type="search"], .navigation-search input[type="search"]:focus {
      background: #fff;
      color: #4d4d4d;
      text-align: center;
      font-size: 50px;
      font-style: bold;
      height: 100px; /* include a height value thats greater than font size */
    }

    And give it a height value.

    #1651226
    Alex

    Thanks, David! The code works just fine, but when the search bar is active, there is no visible cross icon to escape it.

    #1651390
    David
    Staff
    Customer Support

    Add this CSS:

    .search-form.navigation-search.nav-search-active {
      top: 40px;
    }

    And in the CSS above you can adjust the forms height:

    height: 100px; /* include a height value thats greater than font size */

    #1651444
    Alex

    That’s fine, David! You guys and your great team are real coding Jedi πŸ™‚

    #1651547
    David
    Staff
    Customer Support

    Glad to be of help πŸ™‚

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