When you custom Drupal 7 theme, you may want to alter the theme specific settings form to display easier setting methord for customers. So how to alter the Drupal 7 theme-specific settings?

First, you need theme-settings.php under root of theme, which normally is same directory with template.php.

Second, you should use hook_form_system_theme_settings_alter(&$form, &$form_state)

Allow themes to alter the theme-specific settings form.

With this hook, themes can alter the theme-specific settings form in any way allowable by Drupal’s Form API, such as adding form elements, changing default values and removing form elements. See the Form API documentation on api.drupal.org for detailed information.

Note that the base theme’s form alterations will be run before any sub-theme alterations.


$form: Nested array of form elements that comprise the form.

$form_state: A keyed array containing the current state of the form.


modules/system/theme.api.php, line 87


function hook_form_system_theme_settings_alter(&$form, &$form_state) {
  // Add a checkbox to toggle the breadcrumb trail.
  $form['toggle_breadcrumb'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display the breadcrumb'),
    '#default_value' => theme_get_setting('toggle_breadcrumb'),
    '#description' => t('Show a trail of links from the homepage to the current page.'),

Third, here about theme_get_settings() & theme.inc theme_get_setting($setting_name, $theme = NULL)

Retrieves a setting for the current theme or for a given theme.

The final setting is obtained from the last value found in the following sources:

  • the default global settings specified in this function
  • the default theme-specific settings defined in any base theme’s .info file
  • the default theme-specific settings defined in the theme’s .info file
  • the saved values from the global theme settings form
  • the saved values from the theme’s settings form

To only retrieve the default global theme setting, an empty string should be given for $theme.


$setting_name: The name of the setting to be retrieved.

$theme: The name of a given theme; defaults to the current theme.

Return value

The value of the requested setting, NULL if the setting does not exist.


includes/theme.inc, line 1409

The theme system, which controls the output of Drupal.

Forth, we can define theme setting defaults in theme.info file

such as, we add “settings[toggle_breadcrumb] = 1” in theme.info then you will see the toggle_breadcrumb is checked default on theme setting page.

Fifth, we could use this setting value to do some judge and control the theme in page.tpl.php etc. template files.

<?php if (theme_get_setting('toggle_breadcrumb') == '1'): ?>
                <div class="row">
                    <div class="col-md-12">
                        <div id="breadcrumbs"><?php print $breadcrumb; ?> </div>    
<?php endif; ?>

You may also like

Leave A Comment

Please enter your name. Please enter an valid email address. Please enter message.