Without plugins!Copy and paste, 3 minutes, super easy!How to implement dark mode.WordPress

Implement dark mode in WordPress.No plugin is required.

1.JavaScript description.

Put the following js code in the header.

 document.addEventListener('DOMContentLoaded', function() {
            const toggleButtons = document.querySelectorAll('.toggle-mode');

            toggleButtons.forEach(function(button) {
                button.addEventListener('click', function() {
                    const currentMode = localStorage.getItem('data-mode');
                    const newMode = currentMode === 'dark' ? 'light' : 'dark';
                    localStorage.setItem('data-mode', newMode);
                    applySavedMode();
                });
            });
            applySavedMode();
        });
        function applySavedMode() {
            const savedMode = localStorage.getItem('data-mode');
            if (savedMode === 'light') {
                document.documentElement.setAttribute('data-mode', 'light');
            } else if (savedMode === 'dark') {
                document.documentElement.setAttribute('data-mode', 'dark');
            }
        }

2.Css description.

Write the following code in the Css file.

/*Dark mode control*/
html[data-mode="dark"] {
filter: invert(1) hue-rotate(180deg);
}

html[data-mode="dark"] img {
filter: invert(1) hue-rotate(180deg);
}

html[data-mode="dark"] iframe {
filter: invert(1) hue-rotate(180deg);
}

/*Switch icon*/
.toggle-mode{
height: 7px;
padding: 0;
margin: 0;
}

Change the css of the above switching icons to your liking.

3.HTML description.

Write the following code where you want the switching icon (.svg) to appear.The icon is your choice.Be sure to describe the markup, as it will not be inverted unless it is a markup.

<button class="toggle-mode"><svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="25" height="25" viewBox="385 385 30 30"><path d="M400 392.48a7.52 7.52 0 1 0 0 15.04 7.52 7.52 0 0 0 0-15.04z"/><path d="M415 400c-4.58-2.87-5.75-5.48-4.4-10.6-5.12 1.35-7.73.18-10.6-4.4-2.87 4.58-5.48 5.75-10.6 4.4 1.35 5.12.18 7.73-4.4 10.6 4.58 2.87 5.75 5.48 4.4 10.6 5.12-1.35 7.73-.18 10.6 4.4 2.87-4.58 5.48-5.75 10.6-4.4-1.35-5.12-.18-7.73 4.4-10.6zm-15 9.83a9.83 9.83 0 1 1 0-19.66 9.83 9.83 0 0 1 0 19.66z"/></svg></button>

That’s all, and that’s all you need to complete the Dark Mode implementation.

Health

How to live longer.

1. Don’t Cigarette.2. Moderate exercise.3. Nutritious and balanced diet.4. Maintaining a healthy weight.5. Good quality sleep.6. Avoid stress.7. Conclusion. Don’t Cigarette. There are several best ways to live longer, but if asked to choose just one, ‘don’t smoke’, say researchers....

Continue reading

Plant

Aztekium ritteri

1. Habitat2. Description3. Farming Habitat Usually grows on vertical limestone cliffs. It is endemic to two remote small areas in the Nuevo León region of north-eastern Mexico. It is endangered in its habitat due to illegal collection and natural erosion...

Continue reading

Plant Raise

The key points are sun, wind, water and soil! How to grow succulents.

Succulents are very easy to grow compared to other plants. There are four simple points. Maintain in a sunny location. Maintain in a well-ventilated area. Water when the soil is dry. Plant in well-drained soil. As long as the above...

Continue reading

Code Web Without Plugin Woocommerce Wordpress

Without Plugin!How to display just any item on the Woocommerce My Account page.

The items on the Woocommerce My Account page vary depending on the products handled and the site they are on. For example, if you want to hide the ‘Dashboard’ and ‘Downloads’ items, you can achieve this by doing the following....

Continue reading

Plant

Obregonia denegrii.

One genus and one species of cactus, so majestic and dignified is its appearance that it is known as the ‘TEIKAN’. This is a very rare cactus and one of the most popular cacti, partly because of its beautiful rosette...

Continue reading

Code Security Web Wordpress

How to make all pages permanently SSL.WordPress

Has SSL been installed on your website? The introduction of SSL is recommended for all websites because of its security and SEO advantages. Full-page SSL is particularly desirable for shopping and crowdfunding websites where personal data and payments are involved....

Continue reading

Code Web Without Plugin Wordpress

Without plugins!How to implement SEO features.|WordPress

Learn how to introduce policy features in WordPress without using a plugin. Plug-in non-use has various advantages, such as reducing server load and maintaining site display speed. There are many diverse plugins for WordPress, and for SEO, there are excellent...

Continue reading

Code Speed Web Without Plugin Wordpress

Without plugins!How to use syntax highlighting Prism.js.|WordPress

In this article, we will show you how to implement syntax highlighting in WordPress without using a plugin. Syntax highlighting is often used to display source code on websites and blog sites. This website has adopted “Prism.js” after various trials....

Continue reading

Plugin Web Woocommerce Wordpress

Plug-in for exporting and importing CSV WordPress user information.

Use the plugin ‘Import and export users and customers’. Recommended for users who simply want to download user information in CSV format. We have tried several, but so far this plugin is the simplest to use.

Continue reading

Code Speed Web Wordpress

Without plugins!Contact Form 7 How to load js and css only on specified pages.|WordPress

Learn how to make ContactForm7 js and css load only on specified pages in WordPress without using a plugin. Normally, when ContactForm7 is installed, js and css are loaded on every page, which slows down the display speed, but this...

Continue reading

Leave a Reply

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.