Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1474018

    Dear folks,

    I switch the Search Icon to a Search Field with a code I found in the forum:

    add_filter( 'wp_nav_menu_items', 'avia_append_search_nav', 10, 2 );
    
    function avia_append_search_nav ( $items, $args ) {
    	if(avia_get_option('header_searchicon','header_searchicon') != "header_searchicon") return $items;
        if ((is_object($args) && $args->theme_location == 'avia')||  (is_string($args) && $args = "fallback_menu")) {
           	global $avia_config;
           	ob_start();
    		$getform = get_search_form(false);
           	$items .= '<li id="menu-item-search" class="noMobile menu-item menu-item-search-dropdown">'.$getform.'</li>';
    	    }
       	return $items;
    }

    Now my question is: Can I only do this change for a normal expanded menu and keep the Search Icon if the menu switches to the hamburger version? Is there a way to do this? With the code above the Search Field shows above 990px but when the menu changes and is displayed as hamburger, there is nothing. I would like to keep the Icon in this instance. Any help is appreciated. Thanks in advance!

    Kind regards, Daniel

    #1474037

    Hey Daniel,

    Thank you for the inquiry.

    Did you manage to disable the default filters for the search icon? Is your modification working? If so, we can modify the function a bit to include the search icon again and make sure it only displays on mobile view using the available class names (e.g., av-desktop-hide, av-medium-hide, etc.) to control the visibility of elements on different screen sizes:

    add_filter( 'wp_nav_menu_items', 'avia_append_search_nav', 10, 2 );
    
    function avia_append_search_nav($items, $args) {
        if (avia_get_option('header_searchicon', 'header_searchicon') != 'header_searchicon') {
            return $items;
        }
    
        if (avia_get_option('header_position', 'header_top') != 'header_top') {
            return $items;
        }
    
        if ((is_object($args) && $args->theme_location == 'avia') || (is_string($args) && $args == 'fallback_menu')) {
            ob_start();
            $getform = get_search_form(false);  
            $getform = ob_get_clean();  
    
            $items .= '<li id="menu-item-search" class="av-medium-hide av-small-hide av-mini-hide menu-item menu-item-search-dropdown">' . $getform . '</li>';
    
            $items .= '<li id="menu-item-search-icon" class="menu-item menu-item-search-icon av-desktop-hide" role="menuitem">';
            $items .=    '<a aria-label="Search" href="?s=" ' . av_icon_string('search', false) . '>';
            $items .=        '<span class="avia_hidden_link_text">' . __('Search', 'avia_framework') . '</span>';
            $items .=    '</a>';
            $items .= '</li>';
        }
    
        return $items;
    }
    
    

    Best regards,
    Ismael

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