Title: Critical Error: Custom JavaScript is not allowed
Last modified: May 29, 2018

---

# Critical Error: Custom JavaScript is not allowed

 *  Resolved [narinder912](https://wordpress.org/support/users/narinder912/)
 * (@narinder912)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/)
 * Hi
 * I am getting this error in the AMP Validator:
 * “Custom JavaScript is not allowed. CUSTOM_JAVASCRIPT_DISALLOWED
    line 32, column
   1”
 * This is line 32:
 * <script>if (document.location.protocol != “https:”) {document.location = document.
   URL.replace(/^http:/i, “https:”);}</script><script type=’text/javascript’ src
   =’[https://cdn.ampproject.org/v0.js&#8217](https://cdn.ampproject.org/v0.js&#8217);
   async></script>
 * Link to the validator page:
 * [https://validator.ampproject.org/#url=https%3A%2F%2Fwww.desiyatri.com%2Fpattaya-money-exchange%2Fbest-rates%2Famp](https://validator.ampproject.org/#url=https%3A%2F%2Fwww.desiyatri.com%2Fpattaya-money-exchange%2Fbest-rates%2Famp)
 * This error is there for all my pages.
 * Please help.
 * Best Regards
    Narinder

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

 *  [Ryan Kienstra](https://wordpress.org/support/users/ryankienstra/)
 * (@ryankienstra)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10337316)
 * **Thanks, Possible Workaround**
 * Hi [@narinder912](https://wordpress.org/support/users/narinder912/),
    Thanks 
   for bringing this up. Are you using the Really Simple SSL plugin, by chance? 
   It looks like that may be outputting that script.
 * If so, would you be able to put this in your theme’s `functions.php` or a plugin?
   It blocks that script on AMP endpoints only.
 *     ```
       /**
        * Prevents outputting an illegal <script> if this is an AMP endpoint.
        *
        * @param string $script The <script>
        * @return string $script The unchanged <script>, or an empty string if this is on an AMP endpoint.
        */
       add_filter( 'rsssl_javascript_redirect', function( $script ) {
       	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
       		return '';
       	}
       	return $script;
       } );
       ```
   
 *  Thread Starter [narinder912](https://wordpress.org/support/users/narinder912/)
 * (@narinder912)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10337538)
 * Thanks a lot [@ryankienstra](https://wordpress.org/support/users/ryankienstra/)
 * Yes, I am using Really Simple SSL. I did what you said (put the code at the end
   of functions.php) and the AMP test passed in the validator and also in the google
   search AMP test. But I have a question. After this will my pages remain valid‘
   HTTPS’ in all the AMP and non-AMP versions?
 * Please clarify so that I can relax.
    -  This reply was modified 7 years, 11 months ago by [narinder912](https://wordpress.org/support/users/narinder912/).
 *  [Ryan Kienstra](https://wordpress.org/support/users/ryankienstra/)
 * (@ryankienstra)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10337568)
 * **That Code Shouldn’t Apply To Non-AMP Pages**
 * Hi [@narinder912](https://wordpress.org/support/users/narinder912/),
    Thanks 
   for using that code.
 * That code snippet shouldn’t apply to non-AMP pages, because the conditional checks
   that it’s an AMP endpoint.
 * For example, this non-AMP page still redirects to the `https` page (though I’m
   not sure exactly what does that):
 * [http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/](http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/)
 * Also, it looks like AMP pages still appear on the `https` URL, even if you initially
   use `http`:
 * [http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/](http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/)
    -  This reply was modified 7 years, 11 months ago by [Ryan Kienstra](https://wordpress.org/support/users/ryankienstra/).
 *  Thread Starter [narinder912](https://wordpress.org/support/users/narinder912/)
 * (@narinder912)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10337894)
 * Thanks again [@ryankienstra](https://wordpress.org/support/users/ryankienstra/)
 * So, the code you gave is supposed to make the AMP version “http” if I understand
   correctly. But somehow it is not happening.
 * I guess that is good if it continues as it is.
 * But out of curiosity, will Google accept my AMP version pages if they are HTTP
   while the non-AMP version is HTTPS? I don’t actually know what is going on here.
   Should I raise a support ticket with ‘Really Simple SSL’?
 *  [Ryan Kienstra](https://wordpress.org/support/users/ryankienstra/)
 * (@ryankienstra)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10337918)
 * Hi [@narinder912](https://wordpress.org/support/users/narinder912/),
 * > So, the code you gave is supposed to make the AMP version “http” if I understand
   > correctly. But somehow it is not happening.
 * The code snippet I gave only prevents that <script> from appearing on AMP pages:
 * `<script>if (document.location.protocol != “https:”) {document.location = document.
   URL.replace(/^http:/i, “https:”);}</script>`
 * The snippet doesn’t make the AMP version `http`. It looks like it’s appearing
   as `https` (as expected) just fine. Even if you enter an `http` URL:
 * [http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/](http://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/)
 * It apparently redirects to:
 * [https://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/](https://www.desiyatri.com/destination-guides/chiang-mai-blog-desiyatri/amp/)
 * > But out of curiosity, will Google accept my AMP version pages if they are HTTP
   > while the non-AMP version is HTTPS?
 * It doesn’t look like your AMP pages are `http`. The AMP Validator for that URL
   above shows `PASS`:
 * [https://validator.ampproject.org/#url=https%3A%2F%2Fwww.desiyatri.com%2Fdestination-guides%2Fchiang-mai-blog-desiyatri%2Famp%2F](https://validator.ampproject.org/#url=https%3A%2F%2Fwww.desiyatri.com%2Fdestination-guides%2Fchiang-mai-blog-desiyatri%2Famp%2F)
 * > Should I raise a support ticket with ‘Really Simple SSL’?
 * You could. But I think the filter they provide to short-circuit that `<script
   >` is enough.
 *  [wonderewoonwereld](https://wordpress.org/support/users/wonderewoonwereld/)
 * (@wonderewoonwereld)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10366121)
 * Hi There,
 * I have the same problem. I implemented the code in my functions.php file however
   still get an error. Could you please assist?
 * [https://validator.ampproject.org/#url=https%3A%2F%2Fwonderewoonwereld.nl%2Fvelours-bank%2Famp](https://validator.ampproject.org/#url=https%3A%2F%2Fwonderewoonwereld.nl%2Fvelours-bank%2Famp)
 *  [aniket20051989](https://wordpress.org/support/users/aniket20051989/)
 * (@aniket20051989)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10393221)
 * Hi, same error, how do you fixed it? I also applied the code to functions.php.
   
   [https://validator.ampproject.org/#url=https%3A%2F%2Fscreenrant.com%2Fwolverine-scott-eastwood-fan-art-x-men%2Famp%2F](https://validator.ampproject.org/#url=https%3A%2F%2Fscreenrant.com%2Fwolverine-scott-eastwood-fan-art-x-men%2Famp%2F)
 *  [subhashsrs](https://wordpress.org/support/users/subhashsrs/)
 * (@subhashsrs)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10442532)
 * Hi Guys, If you are using SSL plugin, then you can disable javascript as per 
   this screenshot [http://prntscr.com/k07sjp](http://prntscr.com/k07sjp)
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10442569)
 * AMP v0.7.2 was just released which should eliminate this from being an issue.

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

The topic ‘Critical Error: Custom JavaScript is not allowed’ 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/)

 * 9 replies
 * 6 participants
 * Last reply from: [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/critical-error-custom-javascript-is-not-allowed/#post-10442569)
 * Status: resolved