Hi a4e3z2,
Thanks for reaching out!
To detect whether the mode is light or dark using JavaScript, you can use the following method. This example assumes you’re using a custom value (like dracula_mode) saved in localStorage.
Please follow these steps to add the code:
- From your WordPress Dashboard, go to Appearance > Theme File Editor.
- Open the
functions.php file.
- Scroll to the bottom and add the following code:
function prefix_get_dracula_mode() {
?>
<script>
document.addEventListener('DOMContentLoaded', function () {
const draculaMode = localStorage.getItem('dracula_mode');
console.log("Current mode:", draculaMode); // Outputs 'light' or 'dark' if set properly
});
</script>
<?php
}
add_action('wp_footer', 'prefix_get_dracula_mode');
Let us know if you also need help with the toggle logic or setting this value in the first place.