Dark or light theme

My suggestion

We are witnessing that in applications and even websites, there is increasingly a possibility of personal choice whether we want to use a light or dark theme (I personally prefer dark themes and wherever I have the opportunity, I activate the dark theme).

Why wouldn’t CP also allow this to visitors
Most WP and I hope CP themes also allow us to choose a light or dark theme when designing a page.

If not in the core, maybe some plugin (I don’t know if WP already has such a plugin) that will do this task

Best regards

If you go to your Personal Profile page (under Users in the left-hand sidebar in the admin menu), you’ll see that you can choose from a variety of color schemes.

If you want more choices, you can use this website: https://wpadmincolors.com/ or this plugin: ACOS – Custom Admin Color Scheme – WordPress plugin | WordPress.org

I didn’t mean the admin interface (I know that) but that visitors/readers can choose for themselves whether they want a dark and light theme

The color scheme for the front-end of a website is not set by ClassicPress but by the theme being used. It’s up to the authors of the theme you choose to provide that option. In my own custom themes on many sites, I include a dark theme option; it really isn’t hard to do. So I suggest you contact the author of your favorite theme(s) and ask them to provide a dark theme option.

@JerryNidzo,

Further to @timkaye point, perhaps to clarify. A stylesheet can have a section called:

Inside this section, an author could specify overrides to their default theme turning it into a dark theme, which would/should be followed if the OS or Browser is set to make use of a “dark” theme by default. Essentially, the site would use the “dark” scheme instead of the “light” theme assuming the theme itself is by default set to “light”.

Technically a theme developer could go further by specify all “global” theme settings in the core of their theme, then use the above “@media” to specify “dark” and “light” specific settings.

As @timkaye mentioned, this task really does fall to the developer of the theme.

2 Likes

Again, we didn’t understand each other well.
Today, most themes have a light and dark theme that I, as an admin, can choose as the default theme.
But it’s in my interest that a visitor who comes to my site and doesn’t like the dark scene wants a lighter one (or vice versa).
I did a little research on WP plugins and came across a THIS that doesn’t look bad but isn’t exactly perfect, but the question is how long it will be functional on CP
Watch THIS video to see what it looks like

@JerryNidzo,

If the theme is built with a “light/dark” option built into it, then the “visitor” (not admin) should be able to setup their browser or OS with “light” or “dark” mode, which should cause the proper styles to automatically be applied to their session. This type of setup would NOT require the user to “manually” toggle “dark” or “light” on the website itself.

That being said, a developer could also as part of the theme offer some sort of “toggle” option on the page itself for a visitor to switch between the variant of the theme scheme.

As an example of this, I use a control panel (not CP based but just for illustration) where by there is an icon in the menu which when clicked will toggle between “light” or “dark” theme which is pretty nifty. I think it uses a “cookie” to preserve the preference on per user basis, or perhaps saves the setting into a database for the logged in user (I should ask).

So, long story short, I do think I understood your inquiry, still this is a “theme-specific” option, not really a “CP-global” feature as CP doesn’t directly control colors or other aspects of the site, the theme does.

I do suppose someone could technically build a “plugin” to offer this as an option, though it’d still require some degree up theme overriding and might not be as easy as implied to get a theme to change it’s colors as each theme may not setup all aspects of the theme identically. Perhaps it could override some elements though. This would make for a great question for a plugin developer.

2 Likes

to simplify what @tpnsolutions said:

the theme supplies the code for the dark/light theme and this gets activated either on user choice (they toggle a button usually placed in the header part of the site near the menu) or it activates by itself detecting the settings of the browser the visitor is using (I use FireFox Dev Edition and it does that because I set it like this). Usually themes allow for a combo of the two (if user sets browser it falls on browser first but user can always change the behavior at will).

The plugin you found adds some code that changes how a theme works and was developed because in the past themes for WP where much more simple and the choice was left to site owners to add features and whatnot to them (this ended in code snippet galore and sometimes sites got insecure due to this).

Since it is something that in modern era THE THEME IS SUPPOSED TO DO and not ClassicPress, you need to search for WP or CP themes that do have a setting for light/dark theme in them (not all themes ship this feature, this is up to the theme developers).

One theme that does that is Blogtag WP Theme. This theme is developed by user themeansar and generally all their themes do have this toggle and automatic setting.

You just need to look for themes that do the same as his theme does (basically some CSS and a bit of Vanilla JS added to detect browser settings/handle toggle button/change body classes accordingly and display correct color styles in the front-end).

Hope this helps in clarifying.

2 Likes

@JerryNidzo If you’re interested, here is what I did to a test site using the Classic Theme 1.0.0.

Just basic so I can see what it looks like so adapt to your own preferences.

Only added code to functions.php, header.php and created a new css and js file for the toggle.

All the files are placed in my child theme.

functions.php

<?php
function classic_press_child_enqueue_styles() {
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
    wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
}
add_action('wp_enqueue_scripts', 'classic_press_child_enqueue_styles');

// Toggle between light and dark theme on frontend for users
function add_theme_toggle_script() {
    wp_enqueue_script('jquery'); // Ensure jQuery is loaded
    wp_enqueue_script('theme-toggle', get_stylesheet_directory_uri() . '/theme-toggle.js', array('jquery'), '1.0.0', true);
    wp_enqueue_style('theme-toggle-styles', get_stylesheet_directory_uri() . '/theme-toggle.css', array(), '1.0.0');
}
add_action('wp_enqueue_scripts', 'add_theme_toggle_script');

header.php

<?php wp_head(); ?>
	<!-- Theme Toggle Button -->
    <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
    <span class="theme-toggle-dark">🌙</span>
    <span class="theme-toggle-light">☀️</span>
</button>
</head>

CSS

/* CSS Variables for both themes */
:root {
    --background-color: #ffffff;
    --text-color: #333333;
    --link-color: #0073aa;
}

[data-theme="dark"] {
    --background-color: #1a1a1a;
    --text-color: #ffffff;
    --link-color: #00b9eb;
}

/* Apply variables to elements */
body {
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: var(--link-color);
}

/* Theme toggle button styles */
.theme-toggle {
    position: fixed;
    right: 50%;
    transform: translateX(50%) !important; /* Added !important to prevent overrides */
    top: 50px;
    padding: 12px;
    border: 2px solid #666;
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
}

/* Very small screens */
@media screen and (max-width: 600px) {
    .theme-toggle {
        padding: 8px;
        min-width: 70px;
    }
}

/* Light theme styles */
.theme-toggle-light,
.theme-toggle-dark {
    padding: 6px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.theme-toggle-light {
    background: #FFB800;
    display: none;
}

.theme-toggle-dark {
    background: #2C3E50;
    display: inline-block;
}

/* Dark theme specific styles */
[data-theme="dark"] .theme-toggle {
    background: #2C3E50;
    border-color: #888;
    transform: translateX(50%) !important;
}

[data-theme="dark"] .theme-toggle-light {
    display: inline-block;
}

[data-theme="dark"] .theme-toggle-dark {
    display: none;
}

/* Add text label */
.theme-toggle::after {
    content: "Dark Mode";
    font-size: 14px;
    color: #333;
    transition: all 0.3s ease;
}

[data-theme="dark"] .theme-toggle::after {
    content: "Light Mode";
    color: #fff;
}

/* Hover effects */
.theme-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255,255,255,190.7);
}

/* Optional: Add focus styles for accessibility */
.theme-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}

js

jQuery(document).ready(function($) {
    // Check for saved theme preference or default to light
    const currentTheme = localStorage.getItem('theme') || 'light';
    document.documentElement.setAttribute('data-theme', currentTheme);

    // Theme toggle functionality - preventing any position changes
    $('#theme-toggle').click(function(e) {
        e.preventDefault(); // Prevent any default behavior
        const currentTheme = document.documentElement.getAttribute('data-theme');
        const newTheme = currentTheme === 'light' ? 'dark' : 'light';
        
        // Apply new theme without affecting position
        document.documentElement.setAttribute('data-theme', newTheme);
        localStorage.setItem('theme', newTheme);
    });
});

Also the code can be cleaned up most likely as I’m no expert but it seems to work for me. Hope this helps you. And welcome to the community!


4 Likes

@nootkan,

Sounds pretty cool to me.

2 Likes

Wonderful. Thanx for sharing this. :+1:

1 Like

I didn’t want to mess with those codes, but it was easier to solve it with a plugin.
I found some themes that have a dark and light theme switch but they are limited in settings.

I’ll post it here so I don’t have to open a new question.
What does it mean when a widget theme says
This theme has, for example, 2 other widget areas, but this page doesn’t display them”.

Why aren’t these other areas showing up and can it be fixed?

1 Like

It means that those areas are displayed on other posts or pages, but not the one you’re currently on.

1 Like

to see all widget areas go to Appearance > Widgets. It is often the case when you are on a page whose template is with no sidebar (and shows for example only footer like an homepage) while the blog or archive pages do have the sidebar. If you visit the customizer you can click on the menu of your page in the preview to go to a page with sidebar in case you are on one that has no sidebar also, and that should refresh the customizer to show the sidebar on that page so that you can put widgets on it.

2 Likes