|
|
How can I add a custom Google search engine to my site?I've seen some very nice Google-sponsored search systems on sites like StickerGiant and am wondering how hard that is to implement? I know you've written about how to add a Google search box on your site (see How to add a Google search box to your site), but I'm talking about how to have the search results on my site itself. I've been digging into this for Ask Dave Taylor too since I have tons of articles here on the site (over 1500!) and when I look at the questions people have, I know that if you could just dig through the archives, you'd find your answer more easily than waiting forever for me to respond to your question. Funny you'd mention StickerGiant too, because the owner, John Fischer, is a pal of mine. So I got to see how his search works too, and it's really quite simple. The starting place for all of this is the Custom Search Engine page at Google.com. The first step therein is to click on create a custom search engine, at which point you get lots of options. Let's start with the basic configuration options: ![]() Some of these steps are less relevant when you're creating a one-site search engine, but nonetheless, a nice search engine name and description are useful, as are some keywords, requested in the next section: ![]() If your site has information in multiple languages, definitely make sure you choose the predominant language here, and if you're just in English, like I am, then the default works just fine. Next you need to decide if you are going to create a search engine for multiple sites or just one. Since we're doing an on-site engine, let's just stick with one for the results, as you can see: ![]() Since you want to search your entire site, use the notation shown, of www.xxx.com/* (most likely using www.xxx.com will work too, but the "/*" is what Google recommends, so it's best to play by their rules! ![]() As you can see, I'm opting for the free one, because I'm okay with ads showing up in the search results as long as I make a small slice of the revenue stream generated from those advertisers. Finally, it's time to click "Next", at which point you can try out a few searches and ensure it's working, then click "Finish" and you're done! Now the interesting part, customizing the appearance and getting the code you can add to your site so that the search actually works. This is a bit more involved and our next stop on the journey is to get to the list of search engines you've created and click on "Control Panel". Now you'll see a strip of options along the top of the page: Basics | Sites | Refinements | Look and feel | Code | Collaboration | Make money |
&nbps; Business Edition | Advanced | Preview To get the code you need for the page that'll host the search results, click on Code. There are a couple of choices for what kind of behavior you want for the search: You want the default choice of an iframe, which gives you some simple code you can drop on all your pages for the search box and then lets you create a custom template page with code, also from Google, that incorporates the search results. I'm going to create a new template page in Movable Type that includes the search results code so that I can update the data segments easily with latest posting information, etc. Assigning a specific URL to the search results page is a critical step. It looks like this: ![]() Now Google offers up a block of code that implements the search box itself. When I paste it into this blog entry, it results in: Try it if you want, see what happens... The other block of code you get from Google is the code to put in the search results page, and that too is a sequence of mysterious HTML and Javascript. But it's easily added. If you tried a search, above, you've already had a chance to see the resultant page in action. To get it to work, all I added was the following code in the "middle" of the page HTML: <div id="results_013314643351057663050:lozwmpsfbnu"></div>
<script type="text/javascript">
var googleSearchIframeName = "results_013314643351057663050:lozwmpsfbnu"; var googleSearchFormName = "searchbox_013314643351057663050:lozwmpsfbnu"; var googleSearchFrameWidth = 600; var googleSearchFrameborder = 0; var googleSearchDomain = "www.google.com"; var googleSearchPath = "/cse"; </script> <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script> That should get you started with your custom search page. Next up, I'll write about how to tie this into your AdSense account so that you can make a percentage of revenue from the ads on the search results page too. In the meantime, if you don't yet have a Google AdSense account, get one. Start here: Getting started with Google AdSense. Finally, thanks to John at Stickergiant for being so open with sharing how his site works. If you're in the market for bumper stickers, please, check his site out. Fun stuff!
More Useful HTML, JavaScript and Web Site Programming Articles:
✔ How to Create Predefined Google Image Search Links?
Thanks for the Amazon URL [see Creating Amazon Search Links]. That worked beautifully. In fact, I sent you $5.00 for coffee in thanks....
✔ Can I embed a Facebook search box on my blog site?I've seen your articles about how to add a Twitter or Google search box on a Web page, but I have a tougher...
✔ Can I use CSS for drop shadows on my blog?I want to give my site a bit of a facelift and add some neat graphical elements. One of which is drop shadows....
✔ How can I embed interactive photo panoramas on my site/blog?I read through your blog entry about how to take panoramic photos with iOS 6 and an iPhone 5 and got enthused. I've...
✔ How can I create a Twitter search URL shortcut?I'd like to add a few Twitter search links to my Web site. Is that possible, or does Twitter prohibit this sort of...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
Categorized:
HTML, JavaScript and Web Site Programming
(Article 7870,
Written by Dave Taylor)
Tagged: blog search, custom site search, google search Previous: Should my business blog and should I delete critical comments? Next: How can I protect private folders on my Mac? Reader Comments To Date: 22Nasir said, on July 1, 2008 2:49 AM:
Thanks for this useful information. I was looking for this kind of information. Timothy said, on August 3, 2008 7:02 PM:
Thanks alot Dave! You've helped me a few times over the last year or so....BIG THANKS! www.blissent.net Timothy said, on August 3, 2008 7:04 PM:
Thanks alot Dave! You've helped me a few times over the last year or so....BIG THANKS! http://www.blissent.net Uneeb said, on February 6, 2009 9:04 PM:
Min Blowing thanks dave Jean said, on February 24, 2009 1:31 PM:
Yay! It works now. The missing link from Google help, I found here. Thanks! I feel like such a genius now. :) Rajyalakshmi said, on July 4, 2009 3:28 AM:
Hi, Rajyalakshmi said, on July 4, 2009 3:38 AM:
Hi, alanahmad said, on December 23, 2009 1:25 AM:
Chris Hunt said, on January 21, 2010 8:05 AM:
So, did you ever "write about how to tie this into your AdSense account"? I don't see a link. latt said, on January 26, 2010 7:58 PM:
Thank you. Bassile said, on April 5, 2010 12:55 PM:
Hi.. Patrick said, on April 16, 2010 12:45 PM:
Dave, I followed you article to create a custom google search engine for my website. However, I would like the search results webpage to open up in a new window (like your example), but it doesn't. Do you know how to does this? Thanks, P basanta said, on August 23, 2010 5:40 AM:
i want to add my blogs search engine but how it possible help me .................. Wolf said, on September 2, 2010 3:55 PM:
Hi Dave, I'm a veteran running a not for profit project. I'm using my skills to try to help other veterans with PTSD. I want a search bar with no ads on my site - so that it only searches my site content and opens the results in a new window. What's the cheapest that can be done for? cheers Wolf Ivan said, on February 17, 2011 7:41 PM:
This is awesome! I remembered that I had seen a way to search your own site in the past, but the fact that Google offers this tool is very nice. Terry said, on April 26, 2011 10:47 PM:
Thanks so much for the article mate. It worked for me!! Carol said, on October 26, 2011 9:00 AM:
I followed all of the instructions but when I add the code to my website the search bar does not show up. I get "Loading" and an anchor tag and that is all. I am using Dreamweaver, any suggestions? Briggs said, on December 15, 2011 5:51 PM:
I've created a custom HTML link for search result and posted the iframe code.. but when ever a search is performed the custom page doesnt show. i'm done with "open search result in a new page" it leads too many people out of my site.. suraj said, on January 17, 2012 8:44 PM:
how add mp3 search engine for my site.... Silvani BLOG said, on May 28, 2012 11:58 AM:
Hello Taylor, I love this tutorial, its very informatiove. I can't wait to read it. Thanks Soki Briggs said, on September 10, 2012 10:38 AM:
I used the default search bar widget to add google search bar to my blog. i hope they both work the same way
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help Find Me on Google+ ADT on G+ |
O.K.
I can make a searchbar.
I just want to know how to get the html code for it, so I can add the code to my site!