Created
May 25, 2021 07:05
-
-
Save apeschar/bf3a2ab38a04586c264294edd3e983a8 to your computer and use it in GitHub Desktop.
Attempt to fix Twenty Twenty One dark theme flash when using PhastPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Either save this entire file as dark-theme-fix.php and put it inside | |
// wp-content/mu-plugins (you may have to create this directory), | |
// or manually add the script tag to your HTML <HEAD>. | |
add_action('wp_head', function () { ?> | |
<script data-phast-no-defer> | |
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { | |
document.documentElement.classList.add("is-dark-theme"); | |
new MutationObserver(function (mutations, observer) { | |
if (document.body) { | |
document.body.classList.add("is-dark-theme"); | |
observer.disconnect(); | |
} | |
}) | |
.observe(document.documentElement, {childList: true}); | |
} | |
</script> | |
<?php }); |
Thanks @umhan35 for your assistance!
In case anyone sees this: the problem should be fixed in PhastPress 1.123. You should no longer need the code in this gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, Albert. But the code didn't work... But I figured it out -- I just added some JS right after the openning
<body>
tag.Below is the code that works: