Flag This Hub

How To Setup Google Custom Search on Wordpress

By


Replacing default wordpress search with Google Custom Search can be done pretty easily. However, in my case, it was a bumpy road. The main issue was having the search results hosted on my blog instead of directing the results to a google search results page.

Setting Things Up

Create a custom search engine at Google.

Install Google Custom Search Plugin for Wordpress.

Getting The Code

In your control panel for your custom search engine, go to "Get Code" and select the "Host results on my website using an iframe" radio button. In another browser tab, go to your admin. Go to Settings > Google Search. Take the code from the textboxes on the google custom search admin and insert into the corresponding textboxes in your wordpress admin.

Replacing the search box

Also, you need to use the code for your google search box instead of the standard wordpress search box. You can enter this code into a standard text widget in the sidebar, insert it directly into your template, or enter it into the search.php in your template folder.

If your wordpress urls don't require index.php, then the following doesn't apply to you.

I ran into a problem with the iframe search box always wanting to use /search/ instead of /index.php/search/ so I had to go into the plugin and modify a line of code. This url could be '/' as long as we change the way we search through the url, but I imagine it is this way for seo reasons.

// setup user options
self::$search_url = get_option('home') . '/index.php/search/';

Comments

No comments yet.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    Like this Hub?
    Please wait working