Home โ€บPlugins โ€บdark mode block
Dark Mode Block logo

Dark Mode Block

by Erik on WordPress.org

Dark Mode Block is a simple yet powerful WordPress block plugin that allows you to enable dark mode for your website, enhancing readability and reduci …

(4)

Dark Mode Block is a simple yet powerful WordPress block plugin that allows you to enable dark mode for your website, enhancing readability and reducing eye strain without altering your websiteโ€™s colors. Give your users the flexibility to switch between light and dark modes seamlessly.
Designed to be lightweight and efficient the whole frontend script weights less than half of a kb gzipped ๐Ÿ˜‰

Features:
โ€“ Toggle dark mode with a user-friendly icon.
โ€“ Preserve your websiteโ€™s color scheme while improving readability in low-light environments.
โ€“ Enhanced user experience with reduced eye strain.
โ€“ Customizable

Make your website more accessible and user-friendly by offering a dark mode option. With Dark Mode Block, your users can enjoy your content without compromising on aesthetics.

Usage

  1. After activating the plugin, add the โ€œDark Modeโ€ block to your WordPress page or post editor.
  2. Publish or update your content.

Customization

Unleash your creativity! This block is designed to be fully customizable graphically, and since itโ€™s entirely CSS-based, itโ€™s straightforward for anyone to modify and adapt it according to their own taste or template.

You even have control over how the dark mode is applied! Currently, Iโ€™ve applied an invert filter on the background as I donโ€™t know the variables in your template.
However, you have the flexibility to make it even better by setting the text color as the background and vice versa.

Hereโ€™s how to do it:

  1. Add the following code to your functions.php file.
  2. Edit the $custom_css in order to fit your preferences

First dequeue the current style in this way:

add_action( 'wp_enqueue_scripts', function () {
    /** dequeue the default dark mode */
    wp_dequeue_style( 'codekraft-dark-mode-style' );
}, 9 );

Then add yours!

add_action( 'wp_head', function () {
    /** @var {string} $custom_css - your custom css for the dark mode */
    $custom_css = "html.dark-mode body {
        --wp--preset--color--background: #232323;
        --wp--preset--color--foreground: #f3f3f3;
    }
    .dark-mode-switch::before {
        width: 1.6rem;
        cursor: pointer;
        display: flex;
        font-size: 1.6rem;
        line-height: 1.6rem;
        content: '๐ŸŒž'
    }
    .dark-mode .dark-mode-switch::before {
        content: '๐ŸŒš'
    }";
    echo "";
}, 20 );

Please support the plugin posting your custom style and a screenshot in the WordPress support forum section!

Active installations0+
Weekly downloads
19-24.00%
Version0.1.1
Last updated3/6/2024
WordPress version5.7
Tested up to6.4.5
PHP version5.6
Tags
blockcssdark modetheme