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.
CDN Security Speed
DNS configuration with Cloudflare.Set up bombastic DNS for a more comfortable IT life.
DNS configuration with Cloudflare not only speeds up browser start-up, but also contributes to improved security. Please give it a try. 1. 1.1.1.12. 1.1.1.1 family oriented.2.1. Blocks malware.2.2. Blocks malware and adult content. 1.1.1.1 1.1.1.1 is Cloudflare’s public DNS resolver.It...
Continue readingPlant
Agave victoriae-reginae ‘Sasanoyuki’
1. Basic Information.1.1. Scientific name1.2. Family name1.3. Genus name1.4. Species name1.5. Country of origin1.6. Habitat1.7. Morphology1.8. Mature tree1.9. Cold hardy1.10. Heat tolerant1.11. Sunshine1.12. Flour color1.13. Flowering period Basic Information. Scientific name Agave victoria-regina Family name Asparagaceae Genus name Agave Species...
Continue readingNews NGO
Non-governmental organization established.「Frecer NGO」
Today, the non-governmental organisation “Frecer NGO” was established. The aim is to grow and advance humanity while working to solve problems across the globe, whether local, national or international. There are many problems and challenges, but we want to work...
Continue readingPlant
Cool and easy to grow Gymnocalycium Origin, origin and how to grow.
Gymnocalycium is one of the most robust species to manage. It is a cool and varied species with a very good balance of both ornamental and collecting value. 1. Origin2. Habitat3. Features4. Type5. Farming Origin Derived from the Greek ‘gymnòs’...
Continue readingCode 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 readingSpeed Web Wordpress
How to optimise page speed in WordPress.WordPress
If a web page does not load within the first two seconds, 55% of mobile users will leave that web page. Furthermore, around 70% of consumers in online stores report that page display speed is linked to their willingness to...
Continue readingCode 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 readingCode Security Web Wordpress
How to prohibit access to wp-config.php.WordPress
Prohibiting access to wp-config.php improves site security. You are encouraged to refer to this information to maintain your website. Put the following code in the “.htaccess” file. <files wp-config.php> order allow,deny deny from all </files>
Continue readingSpeed Web
Image compression web tool to accelerate website display speed.
There are several ways to improve the display speed of a website, the first effective way is to optimise the size of images. In such cases, it is recommended to use the following image compression web tools. The advantage is...
Continue readingArrival Shop
WordPress PWA(Progressive Web App)Best Plugin!
The right PWA plugin for WordPress can benefit your site and your customers’ experience.This article therefore presents the best PWA plugins for WordPress. 1. 1.Best PWA Plugins For WordPress2. 2.Super Progressive Web Apps By SuperPWA3. 3.Progressive WordPress (PWA) By Nico...
Continue reading