Thanks, Possible Workaround
Hi @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;
} );
Thanks a lot @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.
That Code Shouldn’t Apply To Non-AMP Pages
Hi @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/
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/
Thanks again @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’?
Hi @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/
It apparently redirects to:
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
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.
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
Hi Guys, If you are using SSL plugin, then you can disable javascript as per this screenshot http://prntscr.com/k07sjp
AMP v0.7.2 was just released which should eliminate this from being an issue.