Add a simple search form
Closed this issue · 5 comments
With no widget area, the theme is screaming out for a site search field. If it's a non-fancy form field this shouldn't add more than a few bytes.
Why should this be added?
First, we want people to use Susty (I want to use it!), which means adding basic features such as this.
But, more importantly, having a direct search option is much better than users scrolling through to find something - again, a sustainability advantage here.
I think I may have a solution for this. The following code will add a very simple search option to the top of the menu list...
// Add a search box to the primary menu
function add_search_box( $items, $args ) {
if( $args->theme_location === 'menu-1' ){
$items = '<li class="searchbox-position">' . get_search_form( false ) . '</li>' . $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_search_box', 10, 2 );
I'd consider adding this as a separate page template, like the navigation menu is.
Then it can be added to the nav wherever you like. Or ignored if you don't want it.
Or it could be added to the nav template.
That's a great suggestion. However, the reason why I suggested it this way is that part of maintaining a sustainable site is to reduce down page loads - by adding the search to a new page, rather than an existing one, performing a site search adds an extra page load to the process rather than just the few bytes a search form would take by adding it to the menu.
But, yeah, adding it to the nav template is better than my suggestion - this was more just an example of how it would look/work - if Jack is happy with this I can then add it to the template properly and submit a PR.
I'm actually going to close this off - I'm spinning off a Susty child theme, which will implement changes such as this. However, I'll open this up to Jack to add in any functionality that he think is required for Susty (aware he wants to try and keep it as minimal as possible).
I've been thinking since that it may not be needed. With widgets being turned into blocks, you could add navigation and search to any page you like :)