Adding Google Custom Search to AMP Site

I have 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 do not see any AMP components that enable GCSE to be injected into an AMP site.

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

thank

+3


source to share


3 answers


You are correct, this is not supported yet as it is not in the AMP component list . Try doing a feature request on their githubpage .



+1


source


You can try putting this code on a separate page and then including that page in AMP through the component amp-iframe

. You will also have to comply with the restrictions described here: https://www.ampproject.org/docs/reference/components/amp-iframe



+1


source


Use AMP amp-form component and submit form to Google Custom Search

look at this tutorial

https://gfw-blog.netlify.com/2018/05/11/cse-amp.html

0


source







All Articles