Title: Javascript Rejected by Google Adsense
Last modified: June 25, 2018

---

# Javascript Rejected by Google Adsense

 *  Resolved [bobA1](https://wordpress.org/support/users/boba1/)
 * (@boba1)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/)
 * Google Adsense reports this javascript is “not allowed” by their system, causing
   AMP errors for every post/page in my site. The link above is one example of this
   error out of thousands.
 * `<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' async></script>`
 * The message received says: “Custom JavaScript is not allowed.
    First detected:
   Jun 25, 2018 Status: Error
 * Evidently, Google, your partner in this project, seems to be working against 
   the project and does not support it. This costs me dozens of hours trying to 
   fix these issues, which means basically turning off AMP. Really, please get them
   on the same page, please!
 * Meanwhile, what’s the solution?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fjavascript-rejected-by-google-adsense%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434497)
 * Custom JavaScript is not allowed in AMP. That includes AdSense. If you want to
   serve ads, you should use the amp-ad component: [https://www.ampproject.org/docs/reference/components/amp-ad](https://www.ampproject.org/docs/reference/components/amp-ad)
 * Nevertheless, the JS you have pasted here is not for ads. It’s apparently being
   added by some plugin.
 * Note: As of v1.0 of the plugin there will be a new recommended way to serve AMP
   content on your WordPress site and that is by making use of the new theme support.
   This allows you to fully re-use your active theme’s templates and styles, with
   the added benefit of preventing any AMP-invalid markup (like the above) from 
   being added by a plugin. See [https://github.com/Automattic/amp-wp/wiki/Adding-Theme-Support](https://github.com/Automattic/amp-wp/wiki/Adding-Theme-Support)
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434514)
 * Would you please identify which plugin is adding the above script?
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434548)
 * I believe this may be the same issue as [https://wordpress.org/support/topic/slidedeck-js-not-being-stripped/](https://wordpress.org/support/topic/slidedeck-js-not-being-stripped/)
 * Try adding the following you your theme’s `functions.php`, for example:
 *     ```
       add_action( 'pre_amp_render_post', function() {
           remove_all_actions( 'wp_print_scripts' );
       } );
       ```
   
 *  Thread Starter [bobA1](https://wordpress.org/support/users/boba1/)
 * (@boba1)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434655)
 * The plugin is either AMP itself (note the reference to the javascript is not 
   a 3rd party), or because it refers to https, it could be SSL Secure Content Fixer
   or Really Simple SSL. The latter is a required plugin to prevent the site reverting
   to http. This combination has worked well, however, every so often, Google Adsense
   comes up with these insane AMP errors which oddly resolve as soon as I deactivate
   the AMP plugin. I’ve not added any ‘custom javascript’ as Google contends. I 
   cannot add such code for the place on the site where Google serves the ads because
   it is done by them dynamically.
 * I have added the function in one WP install and await Google Adsense’s reply 
   to revalidation. This can take days.
 *  Thread Starter [bobA1](https://wordpress.org/support/users/boba1/)
 * (@boba1)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434665)
 * BTW, I never said it was ‘for ads’ – only that Google reports that javascript
   code as the cause for them reporting it as improper.
    “Custom JavaScript is not
   allowed.” The email said: “Search Console has identified that your site is affected
   by 1 new AMP related issue. This means that AMP may be negatively affected in
   Google Search results. We encourage you to fix this issue.”
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10434685)
 * The AMP page now shows that it is valid, with that offending JS now being removed:
 * [https://validator.ampproject.org/#url=https%3A%2F%2Fwww.epicurus.com%2Fblog%2Fa-night-at-sardis%2F2434%2Famp%2F](https://validator.ampproject.org/#url=https%3A%2F%2Fwww.epicurus.com%2Fblog%2Fa-night-at-sardis%2F2434%2Famp%2F)
 * The JS is indeed being by the SSL Secure Content Fixer plugin:
 * [https://plugins.trac.wordpress.org/browser/ssl-insecure-content-fixer/tags/2.6.0/includes/class.SSLInsecureContentFixer.php#L241](https://plugins.trac.wordpress.org/browser/ssl-insecure-content-fixer/tags/2.6.0/includes/class.SSLInsecureContentFixer.php#L241)
 * So the workaround above is a good way to fix the problem, and then the permanent
   fix will come in [https://github.com/Automattic/amp-wp/issues/1225](https://github.com/Automattic/amp-wp/issues/1225)
 *  Thread Starter [bobA1](https://wordpress.org/support/users/boba1/)
 * (@boba1)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10436470)
 * Weston,
    Thanks for your help, but, Google rejected your solution. I implemented
   the code snippet and they returned saying it was rejected and that custom javascript
   is not allowed. May I once more reiterate that there is NO custom javascript 
   being added to the site. I have even tried deactivating the plugin, but if AMP
   cannot sustain itself with an https canonical, it has bigger problems than people
   may think. The main question is why Google AdSense and other products suddenly,
   out of the clear blue sky find massive batches of errors all at the same time
   for thousands of sites? We can’t all be using the same plugins?
 * I suppose the best solution is to disregard AMP plugin and replace it with something
   else or no AMP at all. Candidly, I am not giving up on having https vs. http.
   That’s now a standard that AMP must accept, like it or not. I’m sure you concur.
 *  Plugin Author [Weston Ruter](https://wordpress.org/support/users/westonruter/)
 * (@westonruter)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10437189)
 * There is no custom JavaScript on [https://www.epicurus.com/blog/a-night-at-sardis/2434/amp/](https://www.epicurus.com/blog/a-night-at-sardis/2434/amp/)
 * It validates as AMP: [https://validator.ampproject.org/#url=https%3A%2F%2Fwww.epicurus.com%2Fblog%2Fa-night-at-sardis%2F2434%2Famp%2F](https://validator.ampproject.org/#url=https%3A%2F%2Fwww.epicurus.com%2Fblog%2Fa-night-at-sardis%2F2434%2Famp%2F)
 * I suggest you open a topic on a Google product support forum.
 *  Thread Starter [bobA1](https://wordpress.org/support/users/boba1/)
 * (@boba1)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10444854)
 * Weston,
    I will do that but just to let you know, I received another AMP error
   message from them for [https://www.epicurus.com/beverages/raspberry-lemon-sangria/16545/amp/](https://www.epicurus.com/beverages/raspberry-lemon-sangria/16545/amp/).
   It was also a 404, but this is weird. It’s a post scheduled for July 16. This
   system is awful.

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

The topic ‘Javascript Rejected by Google Adsense’ 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

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

 * 9 replies
 * 2 participants
 * Last reply from: [bobA1](https://wordpress.org/support/users/boba1/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/javascript-rejected-by-google-adsense/#post-10444854)
 * Status: resolved