Forcing a theme onto the theme settings form

Ok admittedly most developers will never have to use this trick, but if you ever use color module, or any advanced customization through the theme settings API you will want to do some theming on the theme settings page!

My premium drupal themes in fact do a lot of things with the theme settings form, to name a few:

  • Override the color module stuff to modify the color palette
  • Add a bunch of jQuery scripts to enable live preview of color and layout settings (including a cool animation that resizes the container to any fixed or fluid width)
  • Adding stuff to the form that just needs custom styling, like the Cufon fonts overview

A trend is is recently gaining popularity is the admin theme. There are some great admin themes out there, but unfortunately the admin theme will also load on the theme settings page and spoil the configuration features. In Drupal 7, an admin theme is actually standard, so I was worried I was going to have to write a module to force the theme onto the theme settings page, and I think a theme that requires a module to function is not very elegant, neither is it convenient.

Solution

Frustrated by the growing number of support emails, I figured that even though the admin theme is activated when viewing the theme settings page, the theme-settings.php file is still loading from the theme that is being configured. I dared to try and initialize my theme in the theme-settings.php and it worked! Problem solved, couldn't be simpler.

All you need to do is add 2 lines of code to the top of the theme-settings.php file in your theme (not the admin theme!):

global $custom_theme; $custom_theme = $_SESSION['sooper_prt_syan'];

(Where you replace sooper_prt_syan with the name of your theme)