• Resolved a4e3z2

    (@a4e3z2)


    Hello, I’m having trouble identifying via JavaScript when the mode is light or dark. I know the click event but which one is different? What’s the code for that?

Viewing 1 replies (of 1 total)
  • Plugin Support Sazzad Hossain

    (@sazzad11)

    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:

    1. From your WordPress Dashboard, go to Appearance > Theme File Editor.
    2. Open the functions.php file.
    3. 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.

Viewing 1 replies (of 1 total)

The topic ‘Identify light or dark mode via javascript’ is closed to new replies.