Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Google Custom Search to AMP site

Tags:

amp-html

I have my Google Custom Search Engine (GCSE) code:

<script>
  (function() {
    var cx = '008589157460623253837:mhsjluzrngo';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>

However my Accelerated Mobile Pages (AMP) site does not allow me to add JavaScript to it, and I don't see any AMP components that allow for embedding GCSE into an AMP site.

How can I get GCSE on my site without breaking AMP compliance?

Thanks

like image 523
mCpXZKq3ruqgFXrvvAWRj9cYxk8RLX Avatar asked Oct 18 '22 15:10

mCpXZKq3ruqgFXrvvAWRj9cYxk8RLX


1 Answers

You can try putting that code in a separate page then including that page in your AMP via the amp-iframe component. You will also have to abide by the constraints described here: https://www.ampproject.org/docs/reference/components/amp-iframe

like image 164
ade Avatar answered Oct 21 '22 07:10

ade