Skip to content

Instantly share code, notes, and snippets.

@astockwell
Created January 4, 2013 21:34
Show Gist options
  • Save astockwell/4456409 to your computer and use it in GitHub Desktop.
Save astockwell/4456409 to your computer and use it in GitHub Desktop.
Google Custom Search v2 Include Code for Wordpress - WORKING
<?php get_header(); ?>
<section>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '000000000000000000000:aaa1aa1aa1a';
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>
<!-- Place this tag where you want the search results to render -->
<gcse:searchresults-only linktarget="_parent" queryParameterName="s"></gcse:searchresults-only>
</section>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment