i need to set theme setting programmatically. I use mothership theme. So for example:

$type = theme_get_setting('mothership_classes_view');
//dpm displays 1 - so this setting is checked
//i need to uncheck it, set it to 0

i can't find a function to do this, what is the best way to set it?


3 Answers 3


As you can see in the code of theme_get_settings(), if data is not in cache, it's obtained from variables:

// Get the saved global settings from the database.
$cache[$theme] = array_merge($cache[$theme], variable_get('theme_settings', array()));

if ($theme) {
  // Get the saved theme-specific settings from the database.
  $cache[$theme] = array_merge($cache[$theme], variable_get('theme_' . $theme . '_settings', array()));

So usually when you need to change them from code, you will need to use good old variable_set(). And don't forget to clear the cache.


The actual answer is this:

// Get the settings
$mothership_settings = variable_get('theme_mothership_settings', array());

// Set the variable
$mothership_settings['mothership_classes_view'] = 0;

// Save our settings
variable_set('theme_mothership_settings', $mothership_settings);

This is perfect for an update hook to run, and doesn't seem to (in my case) need a cache clear afterwards.

This can be abstracted to any theme, Drupal stores the settings in the theme_THEMENAME_settings variable. As Pierre mentions, you can also do this in the .info file of the theme but this is only a good idea when you are extending a base theme (as you don't want to overwrite contrib .info files).


You can also set the default value for a theme setting fron the theme .info file.

settings[mothership_classes_view] = foo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.