[Drupal] How to add additional theme settings options to a Drupal 7 theme?

| | 1 min read

You can see certain options in our theme ie in settings page of our Drupal themes like LOGO, SLOGAN etc. We can also add our own options to a theme In this article I will be explaining how to add additional theme settings options to a Drupal 7 theme using hook_form_system_theme_settings_alter.

The hook, hook_form_system_theme_settings_alter() helps to alter the theme's specific settings.Now we may have a confusion, where to execute this code, no worries have the below code in your theme-settings.php. Let's run through it at once.



function mytheme_form_system_theme_settings_alter(&$form, &$form_state) {

  $form['mytheme_width'] = array(

    '#type' => 'radios',

    '#title' => t('Content width'),

    '#options' => array(

    'fluid' => t('Fluid width'),

    'fixed' => t('Fixed width'),

    ),

  '#default_value' => theme_get_setting('mytheme_width'),

  );

}

In the above code we have added an option about the theme width (Fluid width or Fixed width).Here we are using Radio button to select the option.And the options are provided using #options.We can set a default value for this option and this can be done by using the attribute #default_value, here's the brilliant part of it we need to set this value in our .info file.



settings[mytheme_width] = fluid

Thus we get the default value as fluid (as mentioned in our .info file).

Following the above steps we can add more options in theme settings.