Hey guys I’m trying to incorporate Google’s Custom Search with my site. Google provides me with a piece of code and tells me to add it to my site, but I’m not sure where to add it. Do I add it to my header.php file, or do I actually have to add it to all the pages of my site? Also–and this is important, too–is there a specific place in the file(s) I have to add it?
I will appreciate any help you guys can shoot my way. Thanks.
Thanks a lot for this insight Bob. I should have mentioned this before, but I already have a search form in my current theme. Will adding the Google code, say, in the header, get rid of the current search form? I guess I should also mention that I’m no WordPress wizard, so I’m always a bit confused as to how to accomplish these seemingly simple tasks.
Also, I noticed that Google’s Custom Search form says “Custom Search” in the form. Can I get rid of this? Again, I’m thankful for any help.
using the ‘Google Custom Search Plugin’ (http://wordpress.org/extend/plugins/google-custom-search-for-wordpress/) would automatically replace the default search form on your WP-Page. Maybe its an option for you?!
As for the ‘Google custom search’ text: Google loads an background-image into the input-field. I suppose you could get rid of it through your stylesheet:
background-image: none !important;
Or add an image of your own to change the text. :)
Sorry to keep nagging you guys about this but the plugin is not working the way I’d expect. I downloaded the plugin, and under the “Google Search” settings I have two fields that I’m to fill up with code:
1) “Paste code for CSE Search Box
2) “Paste Code for CSE Search Results.”
However, from my Google Custom Search account I’ve been able to locate only one piece of code, which contains a div, some script, and some styles. I pasted this code into the first field, but the plugin did NOT automatically replace my WP search widget. Actually if you don’t mind check out my site: LearnWriter.com and try searching for “MLA template” and you’ll see what’s happening.
Please, please, please let me know what I should do. Thanks in advance.
Lol, I can see what’s going on.
I don’t know why it works this way or if there is a way around it.
Okay I got the two AdSense codes and pasted them where they belong, but there’s still a very serious problem with my site’s search (plz take a look: LearnWriter.com).
I have a clue as to what the problem could be. When setting up AdSense, I had to include a URL to the page I wanted my search results to open in. I wasn’t sure what page to include so I simply pasted the URL of the page I normally get search results in. I think this is what screwed things up, but I can’t say for sure. What URL am I supposed to include if I want search result pages to open within my site? Am I supposed to create a specific page myself? I have zero clue how this works, so again, any help would be greatly appreciated. Thanks!
First, create a copy of the page.php file and rename it t ‘page-search-results.php’. Open page-search-results.php and replace the commented area just after
< ?php with the following comment:
Template Name: Search Results
Now you have a special search-results page template that you can customize.
Now create a page in wordpress called 'Search Results'—before you click 'create', make sure you change the page template to 'Search Results'.
Once that is done, create an adsense account (if you haven't already) and create a Google Custom Search. It will ask you a few questions, like what is the url of the page it will be displayed on, etc. Once this is all done, it will give you two snippets of code. The one snippet is the search box itself—that goes in the header, or sidebar, etc. The second snippet goes on page-search-results.php.
Once you click search, everything should work.
Okay dude thanks a lot. I’m going to do exactly what you said and get back to you. I already have an adsense account, but I didn’t know what page URL to assign for search results. I’m wondering if the 2nd code needs to go in a particular place in the “page-search-results.php” file. Oh well, I’ll figure it out and get back to you ASAP. Thanks again man.
I think you want me to add the “Template name: Search Results” part BEFORE the first “< ?php" in the page right? At the very top of the page?
**Actually I think even the “Template name: Search Results” part has to be contained within a < ?php ?> thing right?
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".