How to modify the code to make the dark mode JS work and be validated by AMP?
-
Hello,
I want to add dark mode to my site, but it looks all dark mode plugins are not compatible with AMP.
So, I start to find relative codes to try to achieve it.
Here is a set of JS which is added to head.php for a dark mode purpose, ref: https://isotropic.co/how-to-add-darkmode-to-any-website-copypaste-darkmodejs/<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script> <script> function addDarkmodeWidget() { new Darkmode().showWidget(); } window.addEventListener('load', addDarkmodeWidget); </script>
I’ve tried to fix the AMP validation errors by modifying the JS code according to AMP coding guide. e.g. <amp-script>, src & target, amp-blind JS.
But it still don’t work. Could you tell me how to modify the code to make the dark mode JS work and be validated by AMP? Or there isn’t any dark mode could be compatible with AMP for now?
PS. For my site running as normal with AMP, above code snippets are deactivated.
Thanks,
GreenThe page I need help with: [log in to see the link]
- The topic ‘How to modify the code to make the dark mode JS work and be validated by AMP?’ is closed to new replies.