Clicky

  1. Home
  2. Developer Docs
  3. Theming (AMP Theme Framework)
  4. How to add custom Scripts in AMP using AMP Theme Framework plugin

How to add custom Scripts in AMP using AMP Theme Framework plugin

First, you need to install the AMP Theme Framework plugin.

After installing you need to enable “Custom AMP Script” for this you need to go WordPress Dashboard -> AMP option panel ->  Settings -> Advance Settings -> Enable “Custom AMP Script” option and then click on the “Save Changes” button.

Custom AMP Script: Once you enable this option amp-script is activated

Use the below functions in a set of the block where you want to use the custom script:

Note: Here $custom_js_url you need to use the URL of the js ( eg: https://example.com/hello-world.js ) and it must be HTTPS.

For example, I’m adding the above code in the “single.php” file of AMP Theme Framework.

Directory: amp-theme-framework\single.php

You need to add below the code In functions.php file of AMP Theme Framework.

Important Note:

  • Here I’m using the if( is_single() ){} condition to display only on the single pages. If you want to display on the other template pages, you can customize this condition and also make sure that the code which I’ve added in the single.php is also added in the other template pages.
  • amp-script is in active development and under experimental availability. It’s subject to breaking API changes and should not yet be used in production.
  • our amp-script elements shouldn’t exceed 150,000 bytes limit if it’s above it will show validation error.
  • In amp-script normal JavaScript is allowed but jQuery is not allowed.

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 October 4, 2019

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

Comments

  1. Good day. I wonder how can i use custom JS AMP script option from your plugin (AMP Theme Framework plugin) ? In plugin that was installed today this function isnt availible. Is it availible in pro-version or already non actual?
    Thank you in advance.
    BR

    1. Hi Vitaly,

      Currently, this function is in the under testing and once the testing is done, we’ll add this in the future updates.

Leave a Comment