Google is the undisputed king of search. They do it well. What many bloggers may not be aware of is that you can use Google as your site’s main search engine. You don’t have to use your blog engine’s built in search.
There are two really nice benefits to using Google for your site search engine:
- It’s Google! That means you have full power of Google search on your blog.
- You can use Adsense for your search results and make some money on your site searches. And the CPM is usually VERY high with Adsense in this case because the ads are super well targeted.
So the question is: how do you do it? Well, I’ll show you.
- You need an Adsense account. So, if you’re not already signed up as an Adsense publisher, do so now.
- In your Adsense account, click on “Adsense Setup”. Then click on “Adsense for Search”.
- Click the “Get Started” button. You will enter the wizard for creating your search form.
- For “Search Type”, select “Only sites I select”. In your “Selected Sites” box, type the URL to your blog. You can enter multiple sites if you wish.
- Enter some “optional keywords” which will gear the ads displayed toward your blog subject matter.
- You can leave all other fields as default. Continue to the next step.
- Choose the look and feel of your search form. Continue to the next step.
- Next, you can choose where you want your search results to appear. In order to make the search results appear within your own site, choose “open results within my own site” and specify the URL. For PCMech, I entered “http://www.pcmech.com/searchresults.php”. This is obviously not part of the WordPress installation, but that’s OK. We’re going to create this file for you in a moment.
- Choose the ad position and color palette and then continue to the next step
- Assign a name to the search engine. This is for your own internal purposes later. Then hit the “Save and Get Code” button.
- You’re going to get two snippets of code. One is for the actual search form and the other is for your search results page. Include the search form HTML wherever you want it to appear in your blog theme (likely either the sidebar or the header). You can use CSS to customize the appearance of the search form to match your site as closely as possible.
- Now you need to create a file called searchresults.php. The code I use for this file is below. You will need to paste in your results code that Google gave you, modify as needed to suite your particular theme, and upload to your blog’s root directory.
<?php
unset($_SERVER['PATH_INFO']);
//Include current WordPress Theme Header etc.
require(‘./wp-config.php’);
function maketitle() {
return ” | Search Results”;
}
//Check if we’re wrapping the WP Theme
//Get Theme settings.
$themes = get_themes();
$current_theme = get_current_theme();
$current_template_dir = $themes[$current_theme]['Template Dir'];
$current_stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
//Initialize the WP class to be able to get the header
wp();
//Set status to 200 to override the 404 set by WordPress
status_header(200);
//Include the WP Header
add_filter(“wp_title”,’maketitle’);
get_header();
?>
[ PASTE YOUR SEARCH RESULTS CODE FROM GOOGLE HERE ]
<?php get_sidebar(); ?>
<?php
get_footer();
?>
This file will use your blog’s active theme, however you may need to do some modifications to suit your blog. You might also need to go back and define the width of the search results to fit your blog.
When you’re done, you will have a Google powered search engine within your blog.
NOTE: The only caveat to keep in mind here is that your posts will not appear in your search engine until Google indexes you. However, if you post often and use the XML Sitemaps plug-in, you should be fine.


