Jump to content

Adding custom google search bar?


Recommended Posts

Hello,

I have created a custom google search bar. That only searches specific sites. I have been trying to put the code in the page where i want it. I have created a page in the CMS and in the page content section i place the code in the html, but nothing ever shows. This is the code:

<script>
 (function() {
var cx = '014664903485936235509:uajjq1fvlsy';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
	'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
 })();
</script>
<gcse:searchresults-only></gcse:searchresults-only>

 

 

This is google's instructions on how to add this to a website's page:

Copy the following code, and paste it into a <div> element in your site's <body> section, where you want the search results to render.

 

Note: For the most cross-browser compatibility, it is recommended that your HTML pages use a supported doctype such as <!DOCTYPE html>. CSS hover effects require a supported doctype.

 

Is this even possible for me to add to my site? Thank you

Link to comment
Share on other sites

you can add this code to your website in many ways, for example:

  1. open the template.tpl file located in your theme directory (for example header.tpl) and insert this code between the {litera}{/literal} tags
  2. download free module like html block and then paste your code to the content block, select position (left column, right column, top, footer, header) and save changes. Search bar should appear automatically. With this method you can also change position of the block with search bar under the modules >positions tab in BO

  • Like 1
Link to comment
Share on other sites

  • 3 years later...
×
×
  • Create New...