- This topic has 3 replies, 2 voices, and was last updated 5 years, 4 months ago by David.
-
AuthorPosts
-
December 19, 2018 at 11:36 pm #761781horst
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!
December 20, 2018 at 6:11 am #761994DavidStaffCustomer SupportHi 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.
December 21, 2018 at 12:22 am #762657horstthanks david,
i did not know, that slideout nav works with widgets, i will give both methods a try!
thanks for your help!
December 21, 2018 at 1:40 am #762706DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.