The AMP specification does not allow custom JavaScript (except for within amp-script
and iframe
). See https://amp.dev/about/how-amp-works/ for why this is a good thing and how AMP works in general.
That’s why the AMP plugin removes any custom JavaScript – otherwise it wouldn’t be valid AMP anymore.
I recommend checking out the extensive documentation on how to develop with the AMP plugin and how you can change how the plugin deals with disallowed markup.