Here are easy steps to add a search bar to a WordPress header. Using the search bar, your site visitors can find what they need in a moment. This post will help you create a search bar in your WordPress site
In most of the WordPress themes, a search box is included by default. But if any theme doesn’t have it or you want to make your own custom search box, you can easily do that too.
How to add a custom search box in WordPress?
- Login to your WordPress admin panel.
- Go to Appearance->editor
- Add the following code to the header.php file.
<?php get_search_form(); ?>
- This will bring in searchform.php if it is present in your theme.
- This will bring the default search that is built-in WordPress to appear in the header. The quality of this search is not great. Continue to read to build a better and faster search experience.
- Signup for a free search demo by entering your URL.
- This will build a search demo.
- Download and Install ExpertRec’s WordPress search plugin from here which will replace your default search form with that of Expertrec’s hosted search.
- Copy-paste your API key from your ExpertRec’s control panel.
- Your new search engine is ready for use.
- If you like to change the ranking or the UI, you can do them easily in your control panel.
- If the plugin method didn’t work, go to the code section inside your WordPress admin panel and add it to your WordPress PHP code. You could also email the code to your WordPress developer to get this added to your site. The <ci-search><ci-search> tag will add the search bar in WordPress header whereas the code within <script></script> adds the search functionality (autocomplete, spell correct, image search etc)
- You can edit the look and feel of your WordPress custom search box by going to https://cse.expertrec.com/csedashboard/looknfeel/inputbox and change the attributes without the need for coding.
- The custom search box for WordPress looks similar to the image below