[Drupal] How to add additional form widgets to theme settings?

| | 1 min read

Many Drupal users wanted to know how to add additional form widgets to their Drupal theme settings. If you are facing the same situation in your Drupal site and want to know how to add additional form widgets to your Drupal site's theme settings then continue reading.

We can customize the settings of our theme from admin/appearance/settings in Drupal 7 and it also contains forms to customize theme settings like the upload logo image. We can add additional form elements to the theme settings form in Drupal 7 by creating a theme-settings.php file in theme's folder and adding the themename_form_system_theme_settings_alter() function.

Follow the steps below to do it.

  1. Create a theme-setings.php in the teme folder.
  2. Add themename_form_system_theme_settings_alter(&$form, $form_state) function.
  3. In this function you can add form elements as usual.
  4. Here is an example code
    function mytheme_form_system_theme_settings_alter(&$form, $form_state) {
    $form['mytheme_test'] = array(
    '#type' => 'select',
    '#title' => t('Title'),
    '#options' => array(
    'default' => t('Default'),
    ),
    '#default_value' => theme_get_setting('mytheme_test'),
    '#description' => t('Enter Description.'),
    );
    }
    ?>
  5. In this example, a select box has been added to the theme settings form and its default value is set through theme_get_settings('settings_name').
  6. To use theme_get_settings(), you need to add the following line in your theme's .info file
    settings[settings_name] = value.
  7. Hope that helps
  8.