Make Search Bar Functional

Suppose we are working with an html template, either one we designed ourselves or perhaps one downloaded from Bootstrap or elsewhere. We have a searchbar which is simply a form. It does not work. No searches are performed.

Here’s how to make the search bar function.

Go to header.php (or where ever the search bar is located). There is probably a block of code that looks something like this:

We are going to put a get method in the <form> tag, and then specify an action by adding action="<?php echo esc_url(); ?>">. Inside the esc_url parentheses we will add the home_url function and pass in a parameter of /. Also, we should give this input a name of s for search as shown in this code::


That’s it! Enter in whatever you are searching for and you will get the results.