WP Choose Your Theme
Let your visitors choose which of your installed themes they see the site with: a dropdown, a list or a single "next theme" link.
Install in
WP Choose Your Theme lets a visitor pick the theme they see your site with, from the themes you installed and allowed. Their choice is remembered in their own browser; you, your other visitors and wp-admin keep using the active theme.
Documentation and source code: github.com/wpbones/wp-chooseyourtheme.
Put the switcher where you want it, in four ways and three looks:
- Block — “Theme Switcher”, in the block editor and in the Site Editor (templates and template parts). The editor shows the real switcher; the sidebar sets the mode and an optional title, and the block follows your text alignment, font size, colours and margin settings. It turns a
[wp_chooseyourtheme]shortcode or the plugin’s widget into a block with one click. - Widget — Appearance › Widgets, “Choose Your Theme”.
- Shortcode —
[wp_chooseyourtheme mode="list"], in a post, a page or a text block. - Template tag —
<?php wp_chooseyourtheme( 'mode=roll' ); ?>, in a theme file such assidebar.php.
The three modes:
menu(the default) — a dropdown. It works without JavaScript, with a button; with JavaScript it changes the theme as soon as you pick one.list— a list of links, one per theme; the current one has the classselected.roll— one link to the next theme, in alphabetical order, going back to the first after the last.
A way back
A template part or a widget area belongs to one theme. If the switcher sits in your active theme’s footer, a visitor who picked another theme gets that theme’s own footer, which may have no switcher, and could be stuck with that look. So, on a page that shows another theme than your own and has no switcher on it, a small bar at the bottom says “You are viewing this site with Twenty Twenty-Four. Back to Twenty Twenty-Five” and the link brings the visitor back, to the same page. It never shows when a switcher is on the page, to a visitor who sees your own theme, in wp-admin or in print. You can turn it off in Appearance › WP Choose Your Theme, or per page with the wp_chooseyourtheme_show_back_link filter.
Safe by default
- A new site offers nothing but its active theme. Open Appearance › WP Choose Your Theme and tick the themes you want visitors to be able to pick. A theme you keep installed for other reasons (an old one, one you are working on) is never public unless you say so.
- A visitor can only ever get a theme you allowed. The browser stores the theme’s folder name; anything else, a theme you did not allow, a theme that is not installed, a child theme whose parent is missing, is ignored and the visitor sees the active theme.
- Only the public site changes. wp-admin, the REST API, Ajax, cron, the login screen, the Customizer and theme previews always use the active theme.
- Block and classic themes are not mixed. They keep templates, menus and widget areas in different places, so a visitor is only offered themes of the same kind as your active theme. (A developer can lift this with the
wp_chooseyourtheme_allow_mixed_kindsfilter.) - The choice is a cookie with
SameSite=LaxandHttpOnly(andSecureon HTTPS), with the lifetime you set, 30 days by default.
Child themes
A child theme is offered like any other theme; the visitor gets the child and, through it, its parent.
Page caching
A page cache keeps one copy of a page and serves it to everyone, so it can serve a visitor the wrong theme. The plugin sends Cache-Control: no-cache and Vary: Cookie on every request that carries the choice cookie, and the redirect that sets the choice is not cacheable either. On a page shown in another theme the plugin also defines DONOTCACHEPAGE, which most caching plugins honour. If your caching plugin or host cache ignores both, set it to skip the cache for visitors who send the wpcyt_theme cookie.
Written by Joobi from the project's own listing. See the source page
1.1.1
- Translations load through WP Bones 3.4.1, which reads the plugin’s
Text DomainandDomain Path; the plugin no longer loads them itself. TheDomain Pathheader now has the leading slash WordPress documents. - Fix: only the block editor’s preview is treated as the editor. A post’s
content.renderedover REST keeps the block’s wrapper, and its switcher links point at the post. - Fix: in the editor the block’s margin and font size no longer apply twice.
- Fix: the way-back bar is no longer fixed over the last line of the page: it sits after it.
- Fix: a page shown in another theme defines
DONOTCACHEPAGE, so a page cache does not keep it for everyone.
1.1.0
- New: the Theme Switcher block (
wp-chooseyourtheme/switcher) for the block editor and the Site Editor: a live preview, the mode and an optional title in the sidebar, alignment, font size, colour and margin settings. A shortcode or the plugin’s widget turns into the block with one click. The shortcode, the widget and the template tag work as before - New: a way back. A visitor who chose another theme, on a page with no switcher (a template part or a widget area belongs to one theme, so the theme they chose may not have it), sees a small bar at the bottom with a link back to your own theme. On by default, also after updating from 1.0.0; turn it off in Appearance › WP Choose Your Theme, or with the
wp_chooseyourtheme_show_back_linkfilter - New: the widget can be read by the block editor, for the one-click conversion to the block
- Changed: where to put the switcher in block and classic themes is answered in the FAQ
- Changed: translations for the block and the new setting, in Italian, Spanish, French, German and Brazilian Portuguese
1.0.0
A rewrite of the plugin for current WordPress, on the WP Bones framework. If you are updating from 0.x, read this.
What stays
- The template tag
wp_chooseyourtheme()and its modesmenu,listandroll, with the same CSS classes (wpcyt_combo,wpcyt_list,wpcyt_roll, the theme name on each list item,selectedon the current one) - Appearance › WP Choose Your Theme is still where you configure it
- Your settings, if 0.x stored them: every theme you had not hidden becomes an allowed theme the first time 1.0 loads. A site without stored 0.x settings is treated as a new installation
What changed
- Requires WordPress 6.6 and PHP 8.1 (0.x did not work on PHP 8: its classes used PHP 4 constructors, which PHP 8 no longer calls, and it relied on
get_themes()andget_current_theme(), deprecated since WordPress 3.4) - New: the choice is stored by theme folder name, in a cookie with
SameSite=LaxandHttpOnly, instead of by theme name in a cookie written by JavaScript. Visitors choose again once: 0.x cookies are not read - New: a theme is applied only if it is allowed, installed and without errors; the active theme is used otherwise. Child themes are applied with their parent
- New: it applies on the public site only, never in wp-admin, the REST API, Ajax, cron, the login screen, the Customizer or theme previews
- New: block themes and classic themes are not mixed: only themes of the same kind as the active one are offered
- New: the choice works without JavaScript, with a link or a form that redirects back to the same page; the dropdown submits itself when JavaScript is on
- New: the shortcode
[wp_chooseyourtheme mode="menu|list|roll"]and a classic widget - New: you set how many days the choice is remembered (30 by default)
- New: pages for visitors who made a choice are sent with
no-cacheandVary: Cookie, so a page cache does not mix visitors up - Changed: you now list the themes that are allowed, not the ones that are hidden. A new installation allows no theme but the active one
- Changed: the settings are saved with a nonce and the
manage_optionscapability, and every value is validated - Changed: every string is translatable; Italian, Spanish, French, German and Brazilian Portuguese are included
- Changed: the plugin removes its options when you delete it
- Removed: the
randmode, which 0.x listed as a future idea and never implemented
0.6
- Rev HTML output for list and roll mode: add slug theme name class
0.5
- Add Admin in backend under Appearance. Rev code and avoid Javascript.
0.2
- Rev
0.1
- First release
Follow this listing's changes (Atom feed)