Disclosure: We are a professional review site that receives compensation from the companies whose products we review. We test each product thoroughly and give high marks to only the very best. We are independently owned and the opinions expressed here are our own.
Do you have a search field on your WordPress site? If not, why not add one. Having your own search engine for your site will help your visitors find what they are looking for and keep them on your site longer. By using a search field, visitors can type in a set of keywords and the on-site search engine will list all topics related to the search. Adding a search field to a WordPress site is essential, as your blog grows, and more posts goes into the archives, a blog becomes harder to navigate and older pages get harder to find. Most visitors are not going to search more than a few pages before giving up and moving on. One of the easiest ways to help your visitors out, is to adda search field plugin or turn on your theme’s search field.
My Theme Doesn’t Have Search Field and I Do Not Want to Add a Plugin
Luckily, my Mystique theme by digitalnature came with one, but several of the other sites I maintain and work on daily did not have search fields and the plugins just didn’t cut it. So I decided that I would use my own search field. I just added a simple PHP line and you can put that line on any page, sidebar, header, or footer and it should work.
[sourcecode language=”PHP”] <?php include(TEMPLATEPATH . "/searchform.php"); ?> [/sourcecode]
The code below works with at least 3 themes. If the code does not work on your site it should create a basic search field.
This is what mine looks like? Results will vary.
Once you have the code in place, you will need to create a search results page, if one was not created by the theme creator. If you do not have a search field provided by your theme, then more than likely you will not have a results page.
How to Create a Search Results Page
1. First thing you need to do is create the search.php file. Open up notepad (windows) or if you want to use something a little more advanced, check out Notepad++ and download the program to edit and create code for your site.
Paste the code below in the document and save it as searchform.php
[sourcecode language=”PHP”]
<?php
/*
Template Name: Search Page
*/
?>
[/sourcecode]
Here is what my searchform.php file opening code looks like.
[sourcecode language=”PHP”]
<?php
/*
Mystique/digitalnature
*/
?>
[/sourcecode]
3. save the file and upload to your theme directory.
4. That should be it. If it doesn’t work, then you might have to create a page and title it ‘Search’ and from the page template drop down menu select the template search page.
NOTE: I have not tested this since I already a search page. After some research, I found that this was the easiest way to make it work. All of my themes came with either a search box and results page or just the results page. Before building the search page, look at your style sheets and make sure you do not have a results pages.
Conclusion
This is just a basic way to create a search box. The results page is basic and you may have to go back and style it to match your site. You may need to add the php code to add the side bars and footers and this will need to be added to the search.php file. But will address how to build a search result page in the future.
Let me know if this works, if it didn’t or I mess up on the code.
Thanks for sharing, James.
This is great but I still prefer using Google search for my site, do you know how to add Search Results Page to our site?