Theme Switcher Component

AI-generated summary

The Theme Switcher Component by B-iggy was introduced to toggle between light and dark modes via a button, originally derived from the Alien Night Theme. Users requested features like admin-configurable themes, logo color switching, and placement customization (e.g., near the search bar or in the user menu). While awesomerobot created a more robust theme toggle using theme IDs, B-iggy acknowledged its superiority and considered his component redundant. However, awesomerobot noted advantages in CSS-based switching (no full refresh needed). Users reported issues: logo color not adapting (Anatolia), layout conflicts (jrgong), and admin panel text invisibility (TheSahil). Feature requests included translation support (Rahim), sidebar compatibility (AquaL1te), and location flexibility (jrgong). B-iggy clarified the component was never meant to toggle full themes but only predefined CSS modes. In post 40, B-iggy officially deprecated the component, recommending the newer Dark/Light Mode Toggle which leverages CSS variables for cleaner, maintainable theme switching. The component remains available but is no longer actively developed.

[deprecated]

Hey Discourse Community,

after a lot of requests I share a Theme Switcher component, encapsulated from my Alien Night Theme.
For now, once pressed the button it will switch your theme into a dark mode theme.

Later on I can maybe implement a setting page, where you can define your own global CSS class your theme should switch into.
Or just toggle between the first two themes you allowed for users to choose from…

Installation & Download

Preview

If you have feedback or questions, just let me know :slight_smile:

23 Likes

You can let admins select which themes they want to use. We have two different themes and each theme has it own dark mode.

When we click the switch to change light to dark, this component below should have change the logo’s color to light as the opposite. Now it doesn’t work with this switch.

https://meta.discourse.org/t/alternative-logo-for-dark-themes/88502

1 Like

Ok, I’m not advanced in Discourse modding but I try to implement it.
Help from professional guys are appreciated :smirk: @Johani

Hmm, good point. Not sure how I can make a cross-component-compatibility-mode.
I’ll think about it.
Thanks for the first feedback so far!

3 Likes

Defining the themes in the settings is possible, but will complicate things. The hamburger menu theme selector is a good working example of how you’d change the theme based on ID.

https://github.com/discourse/discourse-hamburger-theme-selector/blob/master/common/header.html

5 Likes

I had some time tonight, so I worked on modifying the hamburger theme selector to toggle between two themes: https://meta.discourse.org/t/header-theme-toggle/113496. Thanks so much for inspiring this with your theme @B-iggy!

11 Likes

Good Morning @awesomerobot ,
oh wow, that was quick :smile:
Much better than I could have done anyways.

I think this topic here is obsolete/redundant then :thinking:

5 Likes

Not necessarily, there are some benefits of switching the CSS rather than switching the entire theme. Everything’s self contained and you don’t need to fully refresh for all the changes to take effect.

7 Likes

Your component might be better with some improvements. I hope you continue to develop :handshake:

2 Likes

Awesome plugin! How can i force it to be in the first place (next to the search bar)?

1 Like

Good Morning @szergely
glad to hear you like it :slight_smile:

Instead of changing the code on your end I think it makes sense to have it next to the search icon per default.
So I pushed this change now. Let me know if it’s fine :slight_smile:

https://github.com/B-iggy/discourse-theme-switcher/commit/b223cea92fee96ecd0760e0180e03841c79f010c

3 Likes

Yes now its there! Thank you for the fast support, i really like this light/dark button! :heart_eyes:

3 Likes

Unfortunately I can’t edit my own post at the top :roll_eyes:

Hence the important notice that the preview link got updated:

I pushed a new version and the regular “Update to Latest” was broken, so I reinstalled it :roll_eyes:

2 Likes

Made it wiki, you should be able to update it now :hugs:

5 Likes

When using Dark mode with Sam’s minimal theme, it looks like this:

Also is there any workaround to add an alternative logo? My current one is not readable on dark bg, hence I want to add a inverted one for the dark mode

My theme has lots of hardcoded colors and only works properly with a light color scheme. Open to fixing this but for now it does not work right in dark mode.

2 Likes

Any thoughts about making the bottom smaller? When using additional component, it takes a lot of space in the header. For example I like the dark mode button in this ghost theme at top right:

Can i use this also for the material design theme ?

Is there any way to move the plugin from the header to the drop down user panel?

No trivial way, you would need a new component.

1 Like