{"id":160,"date":"2007-09-03T15:13:33","date_gmt":"2007-09-03T22:13:33","guid":{"rendered":"http:\/\/www.1keydata.com\/blog\/2007\/09\/how-to-put-site-search-on-your-website-using-google-custom-search-engine.html"},"modified":"2013-02-04T00:05:00","modified_gmt":"2013-02-04T07:05:00","slug":"how-to-put-site-search-on-your-website-using-google-custom-search-engine","status":"publish","type":"post","link":"https:\/\/www.1keydata.com\/blog\/how-to-put-site-search-on-your-website-using-google-custom-search-engine.html","title":{"rendered":"How to Put Site Search on Your Website Using Google Custom Search Engine"},"content":{"rendered":"<p>A good practice for websites is to include a site search functionality on the site, so your visitors can locate the information they are looking for quickly.  But how to set this up?  And how can I keep the search results on my site so that the visitors don&#8217;t leave? In this post, I will discuss how to set up a site search using Google Custom Search Engine, with the result pages hosted on your own domain. The two key steps are 1) create your custom search engine, and 2) place the code in your website.<\/p>\n<h2><u>Create Custom Search Engine<\/u><\/h2>\n<p>First login to your Google account, then go to your <a href=\"http:\/\/www.google.com\/coop\">Google Coop page<\/a>. Click on the <strong>My Search Engines<\/strong> link under the Create your own search engine header, and click on the <strong>New Search Engine<\/strong> link. You&#8217;ll see the following screen.<\/p>\n<p><!--more--><img border=\"0\" src=\"http:\/\/farm2.static.flickr.com\/1269\/1314687581_71f0b88ff1.jpg\" alt=\"create custom search engine\" \/><\/p>\n<p>On this page, enter the following:<\/p>\n<p><strong>Search engine name<\/strong>: Enter a name for your custom search engine.<\/p>\n<p><strong>Search engine description<\/strong>: Enter a description for your custom search engine.<\/p>\n<p><strong>Search engine keywords<\/strong>: Enter keywords related to the focus of your custom search engine.<\/p>\n<p><strong>Search engine language<\/strong>: Select the primary language of the sites this custom search engine will cover. If your custom search engine covers multiple languages, select <strong>All languages<\/strong>.<\/p>\n<p><strong>What do you want to search?<\/strong> Decide whether you only want to present results from the sites you select, the entire web, or the entire web, emphasizing on the sites you select.<\/p>\n<p><strong>Select some sites<\/strong>: Enter the URL of your site.<\/p>\n<p><strong>Advertising status<\/strong>: Specify whether you want sponsored search ads to appear in your search results. You&#8217;ll typically want to select the <strong>Show ads on results pages<\/strong> option.<\/p>\n<p>Click on <strong>Next<\/strong> to finish the configuration.<\/p>\n<p>On the next page, you can test the custom search engine you just created. Once you are satisfied, click on <strong>Finish<\/strong>. You have just created your own custom search engine.<\/p>\n<h2><u>Place Code on Your Website<\/u><\/h2>\n<p>To get the code you want to put on your website, click on the <strong>Control panel<\/strong> link on your Custom Search Engine home page.<\/p>\n<p>Click on the <strong>Code<\/strong> link. The following page appears.<\/p>\n<p><img border=\"0\" src=\"http:\/\/farm2.static.flickr.com\/1153\/1315571418_f91d4365d6.jpg\" alt=\"control panel google custom search engine\" \/><\/p>\n<p>Click on the plus sign next to <strong>Search box and search results code for your website<\/strong> to expand this section. First you&#8217;ll want to decide how your search box will look like (Google currently offers 7 options). Next, specify the URL for the search results page. This can be any page on your domain. For example, if your domain is http:\/\/www.mysite.com, your search results page can be http:\/\/www.mysite.com\/result.php. After that, you&#8217;ll select the location of sponsored search results (Right, Top and Right, or Top and Bottom).<\/p>\n<p>Now you are ready to paste the code into your site.<\/p>\n<p><strong>Search Box Code<\/strong>: Copy and paste the code in the first box into pages on your site where you want the search box to appear. Two things you might want to change are:<\/p>\n<p>Change the font\/text of the Submit button: Modify the line &lt;input type=&#8221;submit&#8221; name=&#8221;sa&#8221; value=&#8221;Search&#8221; \/&gt;.<br \/>\nChange the size of the search box: Modify size value in &lt;input name=&#8221;q&#8221; type=&#8221;text&#8221; size=&#8221;40&#8243; \/&gt; to your desired size.<\/p>\n<p><strong>Search Results Code<\/strong>: Next, create the search results page. If you want to keep the template of your website in your search results page, make sure you include the template code in the file. Next, copy and paste the code in the second box into the search results page.<\/p>\n<p>To control the width of your search results, include the following inside your &lt;head&gt; tag in your search results page:<\/p>\n<p>&lt;style type=&#8221;text\/css&#8221;&gt;<br \/>\n&lt;!&#8211;<br \/>\n#srchResult iframe {<br \/>\nwidth: 690px;<br \/>\n}<br \/>\n&#8211;&gt;<br \/>\n&lt;\/style&gt;<\/p>\n<p>In addition, just above the code you pasted, add the following line: &lt;div id=&#8221;srchResult&#8221;&gt;. Just below the code, add the following line: &lt;\/div&gt;<\/p>\n<p>Please note that the googleSearchFrameWidth variable does not work; that&#8217;s the reason you need to declare the width via CSS.<\/p>\n<p>Under the <strong>Make Money<\/strong>link, you can associate your Adsense account with your custom search engine. You can also create a separate channel to track your Adsense for Search earnings for this particular custom search engine.<\/p>\n<p>After you are done, first upload your new search results file, and you can submit some queries to see how the results page looks. Once you are satisfied, upload all your pages with the new search box. <strong>Congratulations! You&#8217;ve just added site search functionality to your site.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Provides step-by-step instruction on how to set up a site search for your site using Google custom search engine.  The two key steps are to create the custom search engine, and to place the code on your website.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[322,321,320],"_links":{"self":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/160"}],"collection":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":3,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":693,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions\/693"}],"wp:attachment":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}