News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SMF Theme Toggle

Started by shawnb61, June 21, 2022, 09:30:11 PM

Previous topic - Next topic

shawnb61

Link to the mod

Description:

The SMF Theme Toggle mod lets you easily toggle between the forum default theme and an admin-designated secondary theme with a single click.

This mod works with any theme that allows new entries in the main & profile menus.

This mod works whether or not javascript is enabled on the client.

The requested change is persistent; it works by updating the user's requested theme on their profile.  Users must be allowed to select themes.

Note that menus are cached; you may need to clear cache for this mod to take effect.

Releases:
 - v1.0 Initial release
 - v1.1 Allow admin to select profile menu or main menu
A question worth asking is born in experience & driven by necessity. - Fripp

Steve

Very nifty Shawn.

Can you consider making it so each member can toggle between their two favorite themes in a future version?
My pet rock is not feeling well. I think it's stoned.

shawnb61

Yep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.
A question worth asking is born in experience & driven by necessity. - Fripp

FrizzleFried

I know this is beyond the scope of the current iteration... but would you consider perhaps allowing more than just a toggle between two themes?  My forum runs a total of 5 themes... clicking that button and providing a drop down to select between them would make this mod a 'must have' for my forum...

Just something to consider.

It does work nicely as advertised already.  Thank you.

Steve

That would make the mod a theme changer rather than a toggle between two themes, yes?  :)
My pet rock is not feeling well. I think it's stoned.

FrizzleFried

What is a toggle other than a theme changer but for two themes?

 8)

Arantor

And that's the point, toggling between two things only.

There are theme changer mods out there, either standalone or part of the portal mods.
Holder of controversial views, all of which my own.


FrizzleFried

...but none as elegant.  Again...`twas just a suggestion.  FWIW, I run Tiny Portal currently for the sole reason of the theme changer.  Not elegant.

marcosbr

Quote from: shawnb61 on June 24, 2022, 12:55:45 PMYep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.

I like it
Do you feel superior?
Above is a slab and below is darkness. It's fire brother!
https://amigosdaeletronica.com.br

marcosbr

Is there a way to allow visitors to change the themes? I'm alternating between light and dark.
Do you feel superior?
Above is a slab and below is darkness. It's fire brother!
https://amigosdaeletronica.com.br

marcosbr

Quote from: shawnb61 on June 24, 2022, 12:55:45 PMYep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.

I customized a "copy" of the curve2 theme in dark mode.
Original: https://amigosdaeletronica.com.br
Your MOD is excellent and works well on my official forum.
I would just like permission for visitors!
This image is the "tests" forum with change by the portal.
Test: https://amigosdaeletronica.com/

Do you feel superior?
Above is a slab and below is darkness. It's fire brother!
https://amigosdaeletronica.com.br

marcosbr

I forgot the image

You cannot view this attachment.
Do you feel superior?
Above is a slab and below is darkness. It's fire brother!
https://amigosdaeletronica.com.br

shawnb61

I will look into guest support at some point.  I am in the middle of a few other things I'm looking at atm, so it might be a while.
A question worth asking is born in experience & driven by necessity. - Fripp

Steve

Quote from: FrizzleFried on June 24, 2022, 03:38:09 PM...but none as elegant.  Again...`twas just a suggestion.  FWIW, I run Tiny Portal currently for the sole reason of the theme changer.  Not elegant.
https://custom.simplemachines.org/index.php?mod=3356 - works perfectly and can be placed at the top or bottom of the forum. A small css change can make it centered as well.
My pet rock is not feeling well. I think it's stoned.

Julius_2000

Hi,

I would like to place the theme tog button somewhere else in the menu (outside top dropmenu and thus the burger menu on mobile devices). But for the life of me,  I cannot find  where the themetog function is placed in which php file. I've looked into index.template, Display, and Subs.php to no avail. Any help would be appreciated!

shawnb61

Since this mod is 100% hooks, there isn't an update made to a theme file for you to tweak.  The arrays that contain the menu entries are manipulated directly via hook. 

The current approach is to update the main menu $buttons array via the integrate_menu_buttons hook:
https://github.com/sbulen/SMF-Theme-Toggle/blob/fb788b8f0ae1e4244ba123f5889e532d10527d5c/dist/Sources/ThemeToggleHooks.php#L39

I believe you will want to update the $profile_areas array via the integrate_profile_areas hook.

Then test the bejeebers out of it...
A question worth asking is born in experience & driven by necessity. - Fripp

shawnb61

v1.1 of this mod allows you to place the theme toggle button in the user profile menu. 

At the moment, I'm having some challenges placing this new version on the customization site.

Until this is resolved, feel free to download v1.1 here:
A question worth asking is born in experience & driven by necessity. - Fripp

Julius_2000

Thank you so much, @shawnb61, for making the effort adding it to the menu, really unexpected and appreciated!

I now realize, though, I might have been a bit imprecise in my "request" recently. My intention was to have the toggle button sitting next to the alert and pm buttons (bell & envelope) so it could be readily accessed on mobile, too, without requiring the user to go to a menu first - just like those two. I use Fontawesome icons for these, so it would fit quite nicely on a mobile screen.

shawnb61

Note you no longer need to use the link above.  The link to the mod will now allow you to download the latest version.
A question worth asking is born in experience & driven by necessity. - Fripp

Advertisement: