Hey,
You don’t need to create any search form as WordPress already has a function for it that you can use: https://developer.wordpress.org/reference/functions/get_search_form/
Hope that helps. 🙂
Hi Hardeep,
Thank you for your answer!
however, I would like to have a search from (only search bar) in just one page and not in every pages of the website like a widget or sidebar.
I have a page full with links (about few hundreds), and to access to this page there is a button on the top menu bar. When on this specific page, I would like to have a search bar wich is placed on top of all the links, to make a quick search.
I am not sure that the WordPress function work like that, but if I am wrong, your are welcome to indicate me how it would works 🙂
Thanks!
I believe this is what you are asking for: (using a bootstrap form – if theme is not bootstrap you can remove the classes from the form elements)
<form action="<?php echo home_url( '/' ); ?>" method="get" class="form-inline">
<div class="form-group">
<label class="sr-only" for="search">Search</label>
<input type="search" name="s" id="search" placeholder="<?php _e("Search","theme_name"); ?>" value="<?php the_search_query(); ?>" class="form-control" />
<button type="submit" class="btn btn-info pull-right" style="margin-left:8px;"><?php _e("Search","theme_name"); ?></button>
</div>
</form>
You want to search that page or your your site?
I want the search bar in one page and I want to search articles (site posts/content).
In which case, you can use that function. You can use that function inside your page’s PHP file to add the search bar there. 🙂
Hardeep, thank you! I think the search is somehow in place now, but not sure if it is done correctly. Now, when I search it leads me to a blank page… How could I make the posts appear as result of the search?