Theme Switcher Rules

Allows automatic theme switching based on configurable rules using Drupal's Conditions system.

theme_switcher
5,400 sites
48
drupal.org

Install

Drupal 11, 10, 9, 8 v2.1.0
composer require 'drupal/theme_switcher:^2.1'

Overview

The Theme Switcher Rules module provides a powerful mechanism for automatically switching themes based on customizable rules and conditions. It leverages Drupal's Condition Plugin system, enabling administrators to define complex theme-switching logic using any available condition plugin, including those provided by contributed modules.

Each rule can specify different themes for regular pages and admin pages, and rules are evaluated in a configurable order (by weight). When a rule's conditions are satisfied, the corresponding theme is applied. This makes it possible to use different themes based on content type, user role, language, request path, domain, or any other condition plugin available in the system.

The module is extensible through hooks, allowing developers to filter which conditions are available in the rule configuration form.

Features

  • Create theme-switching rules with a user-friendly admin interface
  • Apply different themes based on Drupal's Condition plugin system (user role, language, request path, node type, etc.)
  • Specify separate themes for admin and non-admin routes within the same rule
  • Drag-and-drop ordering of rules to control evaluation priority
  • Extensible condition system - works with any condition plugin from core or contributed modules
  • Quick enable/disable actions directly from the rule list
  • Automatic cleanup when referenced roles or languages are deleted
  • Hook-based API for filtering available conditions

Use Cases

Different theme per language

Create a rule for each language on your multilingual site. For example, create a rule with the Language condition set to 'English' and select a modern western-style theme, then create another rule for 'Arabic' with an RTL-optimized theme. The rules will automatically switch themes based on the current page language.

Custom theme for specific content types

Apply a specialized theme for certain content types. For example, use a portfolio-style theme for 'Portfolio' nodes and a blog theme for 'Article' nodes. Create separate rules with Node Bundle Type conditions for each content type.

Admin theme override

Use a different admin theme for specific conditions. For example, content editors might prefer a different admin theme than the site default. Create a rule with User Role condition for 'Content Editor' and set only the Admin Theme field.

Domain-specific themes in multisite/domain setups

When using the Domain module or similar, create rules with domain conditions to apply different themes for different domains or subdomains, all within a single Drupal installation.

Restricted pages with different branding

Apply a simplified or branded theme for specific paths. For example, use the Request Path condition to apply a minimal theme to '/checkout/*' pages or a special campaign theme to '/promotion/*' pages.

Role-based theming

Provide different visual experiences based on user roles. For example, premium members could see an enhanced theme while anonymous users see a standard theme. Create rules with User Role conditions for each tier.

Tips

  • Rules are evaluated in weight order (lower weight = higher priority). Use drag-and-drop on the rule list to reorder them.
  • A rule must have at least one theme (regular or admin) configured to have any effect.
  • If no conditions are configured for a rule, it will always match. Place catch-all rules at the bottom with higher weight values.
  • The 'current_theme' condition is automatically excluded to prevent infinite loops.
  • The Language condition only appears when the site has multiple languages configured.
  • When roles or languages are deleted from the system, the module automatically cleans up references in all rules.
  • You can use any condition plugin from contributed modules (like Domain, Group, etc.) to create sophisticated theme switching logic.
  • Set only the Admin Theme if you want a rule to affect only administrative pages while leaving regular pages unchanged.

Technical Details

Admin Pages 4
Theme Switcher /admin/config/system/theme_switcher

Displays a list of all theme switcher rules with their name, machine name, assigned theme, admin theme, and status. Rules can be reordered via drag-and-drop to control evaluation priority. Provides quick enable/disable actions and links to edit or delete each rule.

Add Theme Switcher Rule /admin/config/system/theme_switcher/add

Form for creating a new theme switching rule. Configure the rule name, status, themes to apply, and visibility conditions.

Edit Theme Switcher Rule /admin/config/system/theme_switcher/edit/{theme_switcher_rule}

Form for modifying an existing theme switching rule. All settings except machine name can be changed.

Delete Theme Switcher Rule /admin/config/system/theme_switcher/delete/{theme_switcher_rule}

Confirmation form for deleting a theme switching rule.

Permissions 5
Administer all Theme Switcher Rules

Grants full access to all theme switcher operations including create, view, edit, delete, and reorder rules. This is the master permission that bypasses all other permission checks.

View Theme Switcher Rules

Allows viewing the list of theme switcher rules. Users can see the rules but cannot modify them without additional permissions.

Create Theme Switcher Rules

Allows creating new theme switcher rules. Users need this permission to access the add form.

Edit Theme Switcher Rules

Allows editing existing theme switcher rules. Users need this permission to modify rule settings.

Delete Theme Switcher Rules

Allows deleting theme switcher rules. Users need this permission to remove rules from the system.

Hooks 1
hook_available_conditions_alter

Allows modules to modify the list of conditions available in the theme switcher rule form. This is useful for removing conditions that don't make sense in the context of theme switching or adding custom filtering logic.