Title: Custom JavaScript is not allowed error
Last modified: March 4, 2019

---

# Custom JavaScript is not allowed error

 *  Resolved [dglassman](https://wordpress.org/support/users/dglassman/)
 * (@dglassman)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/)
 * Hi,
 * I am getting “Custom JavaScript is not allowed” for many of my AMP pages. How
   do I fix this?
 * I assume I have to disable JS for these pages but how? Most of the JS I have 
   are loaded via plugins that the site needs to run.
 * I don’t have the Really Simple SSL plugin.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11275147)
 * Please share the URL to an AMP page that has the problem.
 *  Thread Starter [dglassman](https://wordpress.org/support/users/dglassman/)
 * (@dglassman)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11276571)
 * [https://www.diabetesselfmanagement.com/blog/one-of-the-most-effective-diabetes-drugs/amp/](https://www.diabetesselfmanagement.com/blog/one-of-the-most-effective-diabetes-drugs/amp/)
 * This one ^ is also getting hit with: “Only amp-boilerplate and amp-custom ‘style’
   tags are allowed and only in the document head”
 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11276743)
 * Thanks for sharing the URL.
 * The issues seem to be pretty straightforward, let me go through them one by one:
 * First, the “Only amp-boilerplate and amp-custom ‘style’ tags are allowed and 
   only in the document head” issue:
 * In your document’s `<head>`, the following style declaration exists:
 *     ```
       <style>
       			.wp-block-gallery.is-cropped .blocks-gallery-item amp-img > img {
       				object-fit: cover;
       			}
       		</style>
       ```
   
 * You need to find out where this is coming from and insert that CSS using the `
   amp_post_template_css` filter instead of printing it directly.
 * An example of how this filter works can be found at [https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/](https://amp-wp.org/documentation/how-the-plugin-works/classic-templates/).
 * Next up, you are loading a custom JavaScript from Amazon to serve ads. For AMP,
   you need to replace that `<script>` with a dedicated `<amp-ad>`. An example for
   this could be found here: [https://github.com/ampproject/amphtml/blob/master/ads/a9.md](https://github.com/ampproject/amphtml/blob/master/ads/a9.md)
 * Finally, you are loading a custom JavaScript from your own site (`fvm/out/header-
   d5e81391-1551730066.min.js`), containing jQuery and things like Disqus comments.
   You must not load these on the AMP page at all, as it’s not allowed.
 * If you want to use Disqus with AMP, you need to use `<amp-iframe>` to include
   them. You can find an example provided by Disqus here: [https://github.com/disqus/disqus-install-examples/tree/master/google-amp](https://github.com/disqus/disqus-install-examples/tree/master/google-amp)
 * Generally speaking, it’s a good idea to only enqueue scripts and styles when 
   they are actually used on the page. You can use the `is_amp_endpoint()` function
   to check for whether you are on an AMP page or not, and act accordingly. The 
   documentation at [https://amp-wp.org/documentation/playbooks/custom-shortcodes-and-widgets/](https://amp-wp.org/documentation/playbooks/custom-shortcodes-and-widgets/)
   has some examples of how this works.
 * You’ll find that there is tons of other helpful information at [https://amp-wp.org/documentation/getting-started/](https://amp-wp.org/documentation/getting-started/),
   so please take your time to read through the docs.
 *  Thread Starter [dglassman](https://wordpress.org/support/users/dglassman/)
 * (@dglassman)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11281752)
 * Wow! Thank you for that very thorough answer!
 *  Thread Starter [dglassman](https://wordpress.org/support/users/dglassman/)
 * (@dglassman)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11287501)
 * Okay so it took me forever to find out which plugin was causing those issues.
   I had to go one by one disabling them. Is there an easier way?
 * Also, turns out the culprit was NextGen Gallery but I don’t want it disabled.
   How can I keep this plugin active for non-AMP pages but disable it (or its styles
   + javascripts) for AMP only??
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11287547)
 * [@dglassman](https://wordpress.org/support/users/dglassman/) I believe this has
   come up before. Please see: [https://wordpress.org/support/topic/amp-custom-is-missing-in-the-class-amp-gallery-embed-php/#post-11092401](https://wordpress.org/support/topic/amp-custom-is-missing-in-the-class-amp-gallery-embed-php/#post-11092401)
 *  Thread Starter [dglassman](https://wordpress.org/support/users/dglassman/)
 * (@dglassman)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11287574)
 * Absolutely fantastic! Thank you. Worked like a charm.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Custom JavaScript is not allowed error’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [js](https://wordpress.org/support/topic-tag/js/)

 * 7 replies
 * 3 participants
 * Last reply from: [dglassman](https://wordpress.org/support/users/dglassman/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/custom-javascript-is-not-allowed-error/#post-11287574)
 * Status: resolved