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
1<?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.
1234567891011121314<form role="search" method="get" class="searchform group" action="<?phpecho home_url('/');?>"> <label> <span class="offscreen"><?phpecho _x('Search for:', 'label');?></span> <input type="search" class="search-field" placeholder="<?phpecho esc_attr_x('Search', 'placeholder');?>" value="<?phpecho get_search_query();?>" name="s" title="<?phpecho esc_attr_x('Search for:', 'label');?>" /> </label> <input type="image" alt="Submit search query" src="<?phpecho 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- With the wordpress search form plugin- WP Fastest site search.
- 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.
* Please note that this wordpress search form plugin costs 9 USD per month
The following video explains how this could be built using HTML and CSS. The same CSS could be used in the Expertrec control panel to style your functional search box.