[Support request] search in slideout-menu

Home Forums Support [Support request] search in slideout-menu

Home Forums Support search in slideout-menu

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #761781
    horst

    hello,

    i have a question regarding the search (icon)/functionality, but i dont know if its possible without a plugin:

    i want to put the search (only) in the slideout menu.
    i enabled it via customizer, managed to disable the icon via css, then put it in a custom (parent)menu item in the slideout menu. it shows, where it should, but i cannot input search terms.

    i use a second “mobile-menu” for the slideout-menu, a different one as the main-navigation.

    thanks for your help!

    #761994
    David
    Staff
    Customer Support

    Hi there,

    it can be done using this PHP snippet:

    add_action( 'after_setup_theme', 'tu_move_nav_search' );
    function tu_move_nav_search() {
    	remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
    	remove_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' );
    	
    	add_action( 'generate_inside_slideout_navigation', 'generate_navigation_search' );
    	add_action( 'generate_inside_slideout_navigation', 'generate_mobile_menu_search_icon' );
    	
    	remove_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 );
    }
    
    add_filter( 'wp_nav_menu_items', 'tu_slideout_menu_search_icon', 10, 2 );
    function tu_slideout_menu_search_icon( $nav, $args ) {
    	$generate_settings = wp_parse_args(
    		get_option( 'generate_settings', array() ),
    		generate_get_defaults()
    	);
    
    	if ( 'enable' !== $generate_settings['nav_search'] ) {
    		return $nav;
    	}
    
    	if ( $args->theme_location == 'slideout' ) {
    		return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#"><span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '</span></a></li>';
    	}
    
    	return $nav;
    }

    https://docs.generatepress.com/article/adding-php/

    Make sure that the Search is enabled in the Customizer > Layout > Primary Navigation.
    Its not without issues though, for instance the nav search will be restricted to the width of the slideout, also the search icon will be at the bottom and search field at the top of the menu. Re-arranging these can cause issues as the search field gets blocked by the menu items.

    Alternative is to add the standard search widget to the slideout navigation.

    #762657
    horst

    thanks david,

    i did not know, that slideout nav works with widgets, i will give both methods a try!

    thanks for your help!

    #762706
    David
    Staff
    Customer Support

    You’re welcome

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