1. Home
  2. How To
  3. How to add custom scripts in AMP

How to add custom scripts in AMP

There are two ways to include the custom scripts in AMP and in this tutorial I will show you both ways to include the script in AMP.

  1. External Scripts
  2. Inline Scripts

You can add the script with the help of amp-script tag and this lets you to add custom JavaScript to your AMP page while still retaining its lightning-fast speed!

1 – External Scripts

An amp-script element can load a JavaScript file from a URL. This is usually the best way to integrate a script as the browser needs to download the script only once.

Below the script, you need to add posts or pages you want to display amp-script

There is the script in custom_amp.js and in that file, you need to add the scripts like

2 – Inline Scripts

You can also declare scripts inline and reference them by id and
Note that the type needs to be type=text/plain and the target=amp-script like –

Once you created the script then the script won’t work and you will have some error in the console and you just need to add the amp-script-src meta tag

Once you see this error then you just need to copy the key like “sha384 JJ8hybcP8hhYy9N0ruZaJF5DqeLX5R5Aa1Kd4OPrB26C_2Gy33RFc4Z_IBQel0MA” and then you need to go to WordPress Dashboard -> Settings -> Advance Settings -> Enter HTML in Head and then add the meta tag like

Once you add that meta tag then your amp-script will start working in AMP

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on February 21, 2020

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment