How to fix custom JavaScript not allowed in amp pages-min

How to fix custom JavaScript not allowed in amp pages

These errors are called as validation errors in amp. AMP does not allow custom JavaScript to run in amp pages you can use amp-bind or you can exclude scripts and AMP does not support features that rely heavily on JavaScript like script tags, if you received an error in search console you should fix this JavaScript error in amp pages as it slows downs amp & pages with custom JavaScript error or any error will not be indexed in search console some times and will not be included in search console, lets see how to fix this amp error custom JavaScript not allowed in AMP pages.

How to fix custom JavaScript not allowed in amp pages:

If any script tag is include in AMP pages then Search console says custom JavaScript not allowed in amp pages. You can use amp-bind if you want to use JavaScript in AMP pages (which is not recommended as it slows down amp pages).

Step 1: First you should know which script is added in your amp pages and to check you can validate your pages here https://validator.ampproject.org/ or you can check with chrome extension as well.

Step 2: Once you have figured out which script tag is causing this issue, you have to remove the scrip tag from amp.

Step 3: If you don’t want to remove script tag amp supports specific way of using amp JavaScript now, you can code if you really need them on your amp pages.

Note: Including scripts and java scripts in AMP pages will slow down AMP pages which is negative impact on AMP usage. Now google recommends fast loading pages and this is the main reason why publishers will be using AMP pages even though they have website only for fast loading and better performance on mobile devices.

Step 4: Once you have done removing script tag custom JavaScript not allowed in AMP pages will be fixed.

AD

You can cross check with amp validator to confirm JavaScript error is fixed and you can submit amp pages error in search console for validation and fix, search console will identify and fix this issue as validation is successful.

Fix Custom JavaScript not allowed in amp pages for WordPress Website Plugin:

If you are using WordPress plugin like amp for WordPress or any other WordPress plugin for amp pages, now you can easily fix this issue. AMP for WordPress provides you an option of not executing amp scripts by including or excluding JavaScript in AMP pages in very easy way by adding CSS classes.

Advertisement

To exclude JavaScript and fix JavaScript now allowed in amp pages with custom css follow these steps:

Step 1: Open AMP for WordPress plugin

Step 2: Go to Design options

Step 3: Click on Global

Step 4: On right side panel scroll down

Ad

Step 5: At the bottom you can see Advanced options with custom CSS box.

Step 6: Navigate to NON-AMP version of website and find the class using debugging mode and enter the class name here in AMP box. It will not execute custom script tags, if it is mentioned here.

That’s it, once added navigate to amp page and validate your amp page, now you will not be seeing any custom JavaScript is not allowed in amp pages error. Since it is excluded to executed in WordPress amp pages.

Fix Custom JavaScript not allowed in amp pages with w3 Total Cache WordPress Plugin

You can also fix this error by using w3 total cache plugin if you are using it on your WordPress website. Follow the below steps to fix custom JavaScript not allowed in amp.

Step 1: Go to performance in w3 total cache plugin.

Step 2: Now install AMP for WordPress default one.

Step 3: Once amp installed and activated then custom JavaScript will not execute in AMP pages.

Note: If any script tag is present then only custom JavaScript is not allowed in AMP pages error will be triggered in search console.

Why AMP pages doesn’t  Support JavaScript?

AMP is built for fast loading pages and if you use JavaScript and executing JavaScript in AMP pages will slow down AMP fast loading pages.

Can I Use Custom JavaScript in AMP?

You can use if you want by not using script tag, you can use JavaScript by using amp-bind tag.

Cant see Script tag but getting Custom JavaScript error?

If you have script tag then only this error will trigger, do a inspect url in search console and debug which script tag is executing

How to test AMP validation?

You can visit amp Validator org website and check for errors and fix them or use search console live URL inspection tool both are same.