How to build a WordPress search form for your WordPress website that visitors can use to search for content inside your website. In this article, we will see how you can create a custom WordPress search form using two different methods- by adding code, and not adding code. Make sure that you have also read best search engines for WordPress before following the instructions below.
Method 1- WordPress search form by adding code. (Free)
All WordPress sites come with a default search form.
Given that you are here, you want to edit the look and feel of your search form- The placeholder, the submit button, size of the search box, etc you could opt for method 2 which gives you more fine-grained controls.
- You can add a search form by including the following code in your WordPress template
<?php get_search_form(); ?>
- For creating a custom search form, create a new PHP file called searchform.php and save it to your themes folder. You can add the following form code to this file.
<form role="search" method="get" class="searchform group" action="<?php echo home_url('/'); ?>"> <label> <span class="offscreen"><?php echo _x('Search for:', 'label'); ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x('Search', 'placeholder'); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x('Search for:', 'label'); ?>" /> </label> <input type="image" alt="Submit search query" src="<?php echo get_template_directory_uri(); ?>/images/search-icon.png"> </form>
- This adds just a search form to your WordPress site which uses the default WordPress search. To have better search functionality on your WordPress site, you could follow the steps below in method 2.
Method 2- WordPress search form using expertrec custom search engine
- Go to https://cse.expertrec.com/newuser?platform=wordpress
- Enter your website URL and initiate a crawl.
- Wait till all your site pages of your website have been crawled.
- Download and install the WP fastest site search plugin from here.
- Go to https://cse.expertrec.com/csedashboard/home/Status and copy your site ID.
- Click on the site search icon in your WordPress admin panel. Copy-paste your API key from inside your WordPress admin panel
- This plugin adds a better performing search form to your website.
- Subscribe to a paid plan (9 USD per month).
- That’s it, you have added a search form to your WordPress site.
- Now you can go to https://cse.expertrec.com/csedashboard/looknfeel/inputbox and here you will be able to style your wordpress search form the way you want it to look.
Method 3: WordPress search form using plugin
TThe following WordPress plugin adds a WordPress search form.