MyBB Community Forums

Full Version: is this possible to switch themes by a switch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have seen it in many sites that in one switch click them light theme turns into dark mode...

i have installed two themes in my siteĀ 


  1. Emerald Light
  2. Emerald Dark
now my site's current theme is light how can i use this switch options to turna theme into dark without redirecting . Can be it possible without page re-loading ?
No, it's impossible to change theme without reloading.
The theme changement is done by sending via POST the "my_post_key" and "theme" fields.
ok can i turn my light theme to dark by toggle ? how ?
You can use radio buttons or other form elements for theme select instead and style these to look like buttons.
Then use a separate CSS to hide/display the active/inactive theme. This will result in a kind of switch of buttons according to the active one.
<form ...>
<input type="radio" name="theme" value="46" class="switch_light"> Light
<input type="radio" name="theme" value="58" class="switch_dark"> Dark
</form>

Add into Light theme global.css:
.switch_light { display: none; }

Add into Dark theme global.css:
.switch_dark { display: none; }

Mind to use a fixed code for Theme IDs (value=""), else a lot of templates need to be renewed - that will also affect UserCP selects.

Otherwise youcan fell free to add a input button for each theme in a separate form like this
<form method="POST" action="{$theme_redirect_url['location']}" id="theme_select" class="switch_light">
	<input type="hidden" name="theme" value="46">
	<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
	<input type="submit" class="button" value="Light" onclick="MyBB.changeTheme();"">
</form>
<form method="POST" action="{$theme_redirect_url['location']}" id="theme_select" class="switch_dark">
	<input type="hidden" name="theme" value="58">
	<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
	<input type="submit" class="button" value="Dark" onclick="MyBB.changeTheme();"">
</form>

(Just an inspiration, code not tested.)

[ExiTuS]
(2021-03-31, 01:10 PM)[ExiTuS] Wrote: [ -> ]You can use radio buttons or other form elements for theme select instead and style these to look like buttons.
Then use a separate CSS to hide/display the active/inactive theme. This will result in a kind of switch of buttons according to the active one.
<form ...>
<input type="radio" name="theme" value="46" class="switch_light"> Light
<input type="radio" name="theme" value="58" class="switch_dark"> Dark
</form>

Add into Light theme global.css:
.switch_light { display: none; }

Add into Dark theme global.css:
.switch_dark { display: none; }

Mind to use a fixed code for Theme IDs (value=""), else a lot of templates need to be renewed - that will also affect UserCP selects.

Otherwise youcan fell free to add a input button for each theme in a separate form like this
<form method="POST" action="{$theme_redirect_url['location']}" id="theme_select" class="switch_light">
	<input type="hidden" name="theme" value="46">
	<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
	<input type="submit" class="button" value="Light" onclick="MyBB.changeTheme();"">
</form>
<form method="POST" action="{$theme_redirect_url['location']}" id="theme_select" class="switch_dark">
	<input type="hidden" name="theme" value="58">
	<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
	<input type="submit" class="button" value="Dark" onclick="MyBB.changeTheme();"">
</form>

(Just an inspiration, code not tested.)

[ExiTuS]

sounds good...
Let me test is...
Hi PARADOXP,

Did you manage to do the toggle thing ?
I wanted to make this option for next Emerald version like a "turn the light on" option, if you can help me save time <3
Otherwise I'll tell you the solution once I have time to make it.
(2022-10-04, 06:56 PM)AmazOuz Wrote: [ -> ]Hi PARADOXP,

Did you manage to do the toggle thing ?
I wanted to make this option for next Emerald version like a "turn the light on" option, if you can help me save time <3
Otherwise I'll tell you the solution once I have time to make it.

Hey Mate, I hope you are doing well there,

And about the switch the dark/light mode , After a lot of effort i made it successfully done and @Laid help me with that like pushing you heaven from out of hell

You can see the work here :- https://storiespedia.com (don't forget to check the responsive version also)

I have also submitted that theme to MyBB Extend ( https://community.mybb.com/mods.php?acti...w&pid=1469 ) and in a short period i will release the final version of that theme until 1.9 mybb version release.

Thank you and if you need any help , i will be glad to help you.