This is working as intended. Custom JS is not allowed in AMP (unless using amp-script), and will be removed. Thus by default activating AMP with a theme will cause it to behave as if JS is turned off in the browser. To improve the graceful degradation process, in addition to removing custom scripts it will also unwrap noscript elements so that their content becomes the AMP version by default.
You can see the logic here: https://github.com/ampproject/amp-wp/blob/bf8dfc88442a3e66139621ede9f4ccd5bc754c34/includes/sanitizers/class-amp-script-sanitizer.php#L51-L66
Thread Starter
asafm7
(@asafm7)
Thanks for your reply!
So how can I implement a noscript logic on an AMP page?
Meaning, only outputting certain text if JS is truly disabled.
Thanks,
Asaf
I’m noticing that you’re using the amp-gist component in a non-AMP page. What you can do is simply put the noscript inside of the amp-gist. Like so:
<amp-gist data-gistid="400f4d0338a306c5e6db8c1819e78d5d" layout="fixed-height" height="303">
<noscript>
<code>
add_action( 'admin_head', 'set_admin_ip' );
function set_admin_ip() {
$current_admin_ip = $_SERVER['REMOTE_ADDR'];
$saved_admin_ip = get_transient( 'saved_admin_ip' );
if ( ! $saved_admin_ip || $saved_admin_ip !== $current_admin_ip ) {
set_transient( 'saved_admin_ip', $current_admin_ip, 12 * HOUR_IN_SECONDS );
}
}
</code>
</noscript>
</amp-gist>
When noscript appears as a direct child of an AMP component, the unwrapping behavior is prevented. See source.
Thread Starter
asafm7
(@asafm7)
It worked!
Thank you for fast and efficient support!
Feel free to leave the plugin a review!