How To Replace Your WordPress Search With Google

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:

  1. It’s Google! That means you have full power of Google search on your blog.
  2. 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. :)

  1. You need an Adsense account. So, if you’re not already signed up as an Adsense publisher, do so now.
  2. In your Adsense account, click on “Adsense Setup”. Then click on “Adsense for Search”.
  3. Click the “Get Started” button. You will enter the wizard for creating your search form.
  4. 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.
  5. Enter some “optional keywords” which will gear the ads displayed toward your blog subject matter.
  6. You can leave all other fields as default. Continue to the next step.
  7. Choose the look and feel of your search form. Continue to the next step.
  8. 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.
  9. Choose the ad position and color palette and then continue to the next step
  10. Assign a name to the search engine. This is for your own internal purposes later. Then hit the “Save and Get Code” button.
  11. 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.
  12. 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.

Blog Transformation Challenge

Like what you read?

... then take the next step. Register for the 30 Day Blog Transformation Challenge. TRANSFORM your blog by perfecting your writing, optimizing your design, and learning how to optimize the marketing funnel.
Click to Learn More ... or...

  • http://www.seizethepage.com/ Digerati

    Thanks David, I did this for all of my sites, gettingpumped.com – userbytes.com – and of course seizethepage.com

    Thanks.

  • http://www.seizethepage.com Digerati

    Thanks David, I did this for all of my sites, gettingpumped.com – userbytes.com – and of course seizethepage.com

    Thanks.

  • http://SourcesOfInsight.com/ J.D. Meier

    Really good step through.

    It doesn’t look like you’re using it on this blog yet. Is it something you plan to do?

  • http://SourcesOfInsight.com J.D. Meier

    Really good step through.

    It doesn’t look like you’re using it on this blog yet. Is it something you plan to do?

  • http://www.millionairemamas.info/ Malaika Morris

    This is great! Thanks for providing tips on things I can put into action to grow my blogs instead of just posts that make me say oh that’s nice.

  • http://www.millionairemamas.info Malaika Morris

    This is great! Thanks for providing tips on things I can put into action to grow my blogs instead of just posts that make me say oh that’s nice.

  • http://newwpthemes.net/ Susan

    This is a great how to for newbies.

  • http://newwpthemes.net Susan

    This is a great how to for newbies.

  • http://kkomp.com/ Sharron Field

    Thanks so much David for that most useful tip, and the php.

    I’ve added it to kkomp.com .

  • http://kkomp.com Sharron Field

    Thanks so much David for that most useful tip, and the php.

    I’ve added it to kkomp.com .

  • Pingback: links for 2009-01-01 | girlie geek

  • http://www.pcmech.com/ David

    J.D. Meier,
    I probably will do it here. PCMech.com is the place where I did do it, though.

  • http://www.pcmech.com David

    J.D. Meier,
    I probably will do it here. PCMech.com is the place where I did do it, though.

  • http://www.thewebmasterresources.info/ Deca

    Nice tips, I will give it try

  • http://www.thewebmasterresources.info Deca

    Nice tips, I will give it try

  • http://kkomp.com/ Sharron Field

    When I checked the operation of the new Google search I got a parse error:

    ‘Syntax error: Unexpected “/” in line 6′.

    Being a php novice I couldn’t work out exactly what had gone wrong, so I temporarily removed the Google search bars from the blog pending further investigation. I appear to have copied everything exactly, and followed instructions to the letter…?

  • http://kkomp.com Sharron Field

    When I checked the operation of the new Google search I got a parse error:

    ‘Syntax error: Unexpected “/” in line 6′.

    Being a php novice I couldn’t work out exactly what had gone wrong, so I temporarily removed the Google search bars from the blog pending further investigation. I appear to have copied everything exactly, and followed instructions to the letter…?

  • http://www.timelessinformation.com/ Armen Shirvanian

    The great part about this is that it is the whole procedure, for the most part. Someone that wants to make the switch to using Google search on their own site will remember to bookmark this or search for it when they are planning to do it. It makes sense that Google would require AdSense setup before their services could be used.

  • http://www.timelessinformation.com Armen Shirvanian

    The great part about this is that it is the whole procedure, for the most part. Someone that wants to make the switch to using Google search on their own site will remember to bookmark this or search for it when they are planning to do it. It makes sense that Google would require AdSense setup before their services could be used.

  • http://www.networkmarketinginreview.com/ Malaika Morris

    Has anyone else figured out how to correct this error. It’s similar to the one Sharron had above

    Parse error: syntax error, unexpected ‘/’ in … on line 4

    I keep changing things but can’t get it to work.

    Thanks.

  • http://www.networkmarketinginreview.com Malaika Morris

    Has anyone else figured out how to correct this error. It’s similar to the one Sharron had above

    Parse error: syntax error, unexpected ‘/’ in … on line 4

    I keep changing things but can’t get it to work.

    Thanks.

  • http://kkomp.com/ Sharron Field

    In reply to Malaika Morris:

    This is rather weird; as your script is seemingly showing a syntax error on line 4, from what I read above, and mine is showing on line 6. As far as I can see there are no instances of “/” on lines 4 or 6; unless I’m reading it wrong. I take it we’re both using the same script?

    I’m still a php ameteur at best; so I’ve shelved this project for now pending review on David’s return. The search results page script is still on my server, but I’ve removed the search box scripts from the pages and sidebar where I’d inserted them for the time being as they’re not working and returning the parse error.

  • http://kkomp.com Sharron Field

    In reply to Malaika Morris:

    This is rather weird; as your script is seemingly showing a syntax error on line 4, from what I read above, and mine is showing on line 6. As far as I can see there are no instances of “/” on lines 4 or 6; unless I’m reading it wrong. I take it we’re both using the same script?

    I’m still a php ameteur at best; so I’ve shelved this project for now pending review on David’s return. The search results page script is still on my server, but I’ve removed the search box scripts from the pages and sidebar where I’d inserted them for the time being as they’re not working and returning the parse error.

  • http://buzvia.com/2xStocks.com Jon

    An even better strategy is to use Google to search across a network of your sites if you have more than one… something I am working on at the moment.

    Jon
    http://2xStocks.com
    Doubling my money, one stock at a time

  • http://buzvia.com/2xStocks.com Jon

    An even better strategy is to use Google to search across a network of your sites if you have more than one… something I am working on at the moment.

    Jon
    http://2xStocks.com
    Doubling my money, one stock at a time

  • http://www.kco1.net/blog Kathleane

    Jon, please let us know more about your plan to use Google to search across a network of sits. I’d love to do something like that for several of my sites.

    To those with parsing errors: I’m receiving the same error and have had to remove the Google search boxes until I get it figured out or a post here gives the solution. Anyone with any ideas? I’m willing to try various things and promise not to flame you if it doesn’t work (:

  • http://www.kco1.net/blog Kathleane

    Jon, please let us know more about your plan to use Google to search across a network of sits. I’d love to do something like that for several of my sites.

    To those with parsing errors: I’m receiving the same error and have had to remove the Google search boxes until I get it figured out or a post here gives the solution. Anyone with any ideas? I’m willing to try various things and promise not to flame you if it doesn’t work (:

  • http://www.travel-china.net/ Chinese Girl

    I like the idea, but it seems quite hard to change the style of google search results page, while my theme has very nice layout of search results.

  • http://www.travel-china.net Chinese Girl

    I like the idea, but it seems quite hard to change the style of google search results page, while my theme has very nice layout of search results.

  • http://vutong.com/ Vu Tong

    Thank you so much for this alternative for integrating Google Search into WordPress.

    So far it’s working great on my blog.

  • http://vutong.com Vu Tong

    Thank you so much for this alternative for integrating Google Search into WordPress.

    So far it’s working great on my blog.

  • http://www.carvalencia.net/ carvlc

    Hi David,

    Thank you for the tip. I agree with you, that many bloggers certainly are not aware of the fact, that they can use Google as their search engine.

  • http://www.carvalencia.net carvlc

    Hi David,

    Thank you for the tip. I agree with you, that many bloggers certainly are not aware of the fact, that they can use Google as their search engine.

  • http://www.simplygigs.com Mike

    For those with the parsing errors, if you just did a copy and paste on the code you need to manually edit the searchresults.php file with a text editor and change the ‘s in line’s 4 and 6. If you need more help post your error.

  • http://www.simplygigs.com/ Mike

    For those with the parsing errors, if you just did a copy and paste on the code you need to manually edit the searchresults.php file with a text editor and change the ‘s in line’s 4 and 6. If you need more help post your error.

  • http://www.network---marketing.com/ Cathy

    Hmmmm. I tried this, but not all of my pages appear to be indexed. I guess this won’t work for me. Bummer :( Will doing this cause google to hit my site more and better index it? I look at network traffic and see a ton from google, yet still not all my pages are returning.

  • http://www.network---marketing.com Cathy

    Hmmmm. I tried this, but not all of my pages appear to be indexed. I guess this won’t work for me. Bummer :( Will doing this cause google to hit my site more and better index it? I look at network traffic and see a ton from google, yet still not all my pages are returning.

  • http://www.abeontech.com/ Abeon Tech

    Very usefull tutorial. My adsense for search eCPM is always higher than adsense for content… This should boost my earning a little :-)

  • http://www.abeontech.com/ Abeon Tech

    Very usefull tutorial. My adsense for search eCPM is always higher than adsense for content… This should boost my earning a little :-)

  • http://truetrafficsecrets.com/ Kevin Baker

    Hi David,

    I confess this had never even entered my head to do. But its a neat way to make sure that your visitors can search with the most powerful engine online.

    I am not myself a Fan of adsense though. I find adsense too low on the money earning tree to be of any serious use, unless you have a whole bunch of specialty blogs, then it adds up.

    Thanks for the tip

  • http://truetrafficsecrets.com Kevin Baker

    Hi David,

    I confess this had never even entered my head to do. But its a neat way to make sure that your visitors can search with the most powerful engine online.

    I am not myself a Fan of adsense though. I find adsense too low on the money earning tree to be of any serious use, unless you have a whole bunch of specialty blogs, then it adds up.

    Thanks for the tip

  • http://mlmtrafficandleadsystem.com/ Vincent Adams

    David thanks, you give some great information. I am about to start a new self hosted WP blog and I will definitely use a Google search box.

  • http://mlmtrafficandleadsystem.com Vincent Adams

    David thanks, you give some great information. I am about to start a new self hosted WP blog and I will definitely use a Google search box.

  • http://boatauctionsdirect.com/ Boat Rod

    Yeah, same here. I would add the search for visitor value but adsense in the past only served to diluted site sales. But a great tool for visitor value nonetheless

  • http://boatauctionsdirect.com Boat Rod

    Yeah, same here. I would add the search for visitor value but adsense in the past only served to diluted site sales. But a great tool for visitor value nonetheless

  • http://artoftheiphone.com/ Alan

    I too was getting the following error:

    'Syntax error: Unexpected “/” in line 4'.

    You need to change the apostrophes in this line (line 4) to quotation marks to fix this.

    So where it says:

    require('./wp-config.php');

    Change both the apostrophes to quotation marks.

    For those who are getting the line 6 error, I suspect the converse is true. You need to change to quotation marks to apostrophes, but I'm not entirely sure.

    Thank you for this tutorial. I had problems getting this to look right with my website. The header appears fine, but the sidebar does not appear correctly, it appears below the search results. I simply removed the sidebar code. I also had to center the search results in the searchresults.php to get it to look half decent. It's a bit rough looking–the iFrame looks kind of dumb in general–but it gets the job done.

  • dX

    Don't forget to go into general-template.php to modify function get_search_form() with your new Google search form.

  • http://www.rainbowskill.com/ Rainbowskill

    This is great! Very useful tutorial.Thanks for the post and for providing such useful tips. Thanks for the post.

  • not working for me.

    im getting a 404 error when doing a search. guess I did something wrong.

  • MD

    I was looking for ways to include Google Search in my WordPress Blog and have found your post which is very interesting. You are describing process where template url searchresulst.php is used directly without mentioning need for creation of actual page.

    Are you saying that this url is sufficient and static page using template searchresults.php is not needed? If so, this is most useful piece of advice on this topic I have found to date.