Forums › Forums › Search & Filter Pro › Add searchform to menu
- This topic has 5 replies, 2 voices, and was last updated 5 years, 8 months ago by
Trevor.
-
Trevor(Private) January 28, 2020 at 12:46 pm #232322
There are three ways:
1. Add a shortcode.
2. Change the HTML of the search already in the menu to send to a Search & Filter results/search page.
3. Use a WordPress re-write to send to a Search & Filter results/search page.Which do you think would be best for you?
Anonymous(Private) January 30, 2020 at 5:11 pm #232621This is the code in my child theme’s function.php that I added to add the search form:
add_theme_support( ‘html5’, array( ‘search-form’ ) );
add_filter(‘wp_nav_menu_items’, ‘add_search_form_to_menu’, 10, 2);
function add_search_form_to_menu($items, $args) {
// If this isn’t the main navbar menu, do nothing
if( !($args->theme_location == ‘main’) ) // with Customizr Pro 1.2+ and Cusomizr 3.4+ you can chose to display the saerch box to the secondary menu, just replacing ‘main’ with ‘secondary’
return $items;
// On main menu: put styling around search and append it to the menu items
return $items . ‘<li class=”my-nav-menu-search”>’ . get_search_form(false) . ‘‘;
} -
AuthorPosts