Archived topic
always show search box (make it show without having to click icon)
5 replies · Started by Webmaster on April 19, 2020
May you please share function / snippet to "always show" search box without having to click the icon? Perhaps remove the icon all together too. I just think it would be great for visitors to have one less click to worry about ;)
<li class="search-item"><a aria-label="Open Search Bar" href="#"></a></li>
If something like this isn't easily achieved with minimal effort, no worries. I tried searching the site before posting but it's becoming very hard to use the search box, the displayed data is not always relevant / easy to read. So I did a search query with Duckduckgo and still didn't have any success.
https://duckduckgo.com/?q=site%3Ageneratepress.com+always+display+search+box
Hi there,
Wouldn't this make it so your other menu items couldn't be clicked? Or would you want the search box to appear below the navigation?
Let me know :)
Like this: 
You know, I might have better success with just finding out how to add a search box with in GP Hook. https://developer.wordpress.org/reference/functions/get_search_form/
I thought it would make sense to just use what was already there... but maybe not.
Hi there,
you can add a search form to the inside_navigation hook using this function:
add_action( 'generate_inside_navigation','db_navigation_search' );
function db_navigation_search() { ?>
<form role="search" method="get" id="searchform"
class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit"
value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
<?php }
Alternatively you can use a Hook Element and just add the HTML within that function.
Then some CSS to align it to the right of the menu:
.inside-navigation {
display: flex;
}
.inside-navigation form {
order: 5;
}
Any chance you can link us to your site so we can give you specific CSS?
Thanks!