8.5.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.0.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.1.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.2.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.3.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.4.x theme.inc theme_get_setting($setting_name, $theme = NULL)
8.6.x theme.inc theme_get_setting($setting_name, $theme = NULL)
4.6.x theme.inc theme_get_setting($setting_name, $refresh = FALSE)
4.7.x theme.inc theme_get_setting($setting_name, $refresh = FALSE)
5.x theme.inc theme_get_setting($setting_name, $refresh = FALSE)
6.x theme.inc theme_get_setting($setting_name, $refresh = FALSE)
7.x 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.

Parameters

$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.

12 calls to theme_get_setting()
bartik_process_maintenance_page in themes/bartik/template.php
Override or insert variables into the maintenance page template.
bartik_process_page in themes/bartik/template.php
Override or insert variables into the page template.
color.inc in themes/bartik/color/color.inc
garland_form_system_theme_settings_alter in themes/garland/theme-settings.php
Implements hook_form_FORM_ID_alter().
hook_form_system_theme_settings_alter in modules/system/theme.api.php
Allow themes to alter the theme-specific settings form.

... See full list

File

includes/theme.inc, line 1410
The theme system, which controls the output of Drupal.

Code

function theme_get_setting($setting_name, $theme = NULL) {
  $cache =& drupal_static(__FUNCTION__, array());

  // If no key is given, use the current theme if we can determine it.
  if (!isset($theme)) {
    $theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : '';
  }
  if (empty($cache[$theme])) {

    // Set the default values for each global setting.
    // To add new global settings, add their default values below, and then
    // add form elements to system_theme_settings() in system.admin.inc.
    $cache[$theme] = array(
      'default_logo' => 1,
      'logo_path' => '',
      'default_favicon' => 1,
      'favicon_path' => '',
      // Use the IANA-registered MIME type for ICO files as default.
      'favicon_mimetype' => 'image/vnd.microsoft.icon',
    );

    // Turn on all default features.
    $features = _system_default_theme_features();
    foreach ($features as $feature) {
      $cache[$theme]['toggle_' . $feature] = 1;
    }

    // Get the values for the theme-specific settings from the .info files of
    // the theme and all its base themes.
    if ($theme) {
      $themes = list_themes();
      $theme_object = $themes[$theme];

      // Create a list which includes the current theme and all its base themes.
      if (isset($theme_object->base_themes)) {
        $theme_keys = array_keys($theme_object->base_themes);
        $theme_keys[] = $theme;
      }
      else {
        $theme_keys = array(
          $theme,
        );
      }
      foreach ($theme_keys as $theme_key) {
        if (!empty($themes[$theme_key]->info['settings'])) {
          $cache[$theme] = array_merge($cache[$theme], $themes[$theme_key]->info['settings']);
        }
      }
    }

    // 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()));

      // If the theme does not support a particular feature, override the global
      // setting and set the value to NULL.
      if (!empty($theme_object->info['features'])) {
        foreach ($features as $feature) {
          if (!in_array($feature, $theme_object->info['features'])) {
            $cache[$theme]['toggle_' . $feature] = NULL;
          }
        }
      }

      // Generate the path to the logo image.
      if ($cache[$theme]['toggle_logo']) {
        if ($cache[$theme]['default_logo']) {
          $cache[$theme]['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png');
        }
        elseif ($cache[$theme]['logo_path']) {
          $cache[$theme]['logo'] = file_create_url($cache[$theme]['logo_path']);
        }
      }

      // Generate the path to the favicon.
      if ($cache[$theme]['toggle_favicon']) {
        if ($cache[$theme]['default_favicon']) {
          if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
            $cache[$theme]['favicon'] = file_create_url($favicon);
          }
          else {
            $cache[$theme]['favicon'] = file_create_url('misc/favicon.ico');
          }
        }
        elseif ($cache[$theme]['favicon_path']) {
          $cache[$theme]['favicon'] = file_create_url($cache[$theme]['favicon_path']);
        }
        else {
          $cache[$theme]['toggle_favicon'] = FALSE;
        }
      }
    }
  }
  return isset($cache[$theme][$setting_name]) ? $cache[$theme][$setting_name] : NULL;
}

Comments

rachanakamlesh’s picture

Hi,
If you would like to add image upload in your theme settings inside Admin area and need to use on front-end:
Go to your theme folder and open the file theme-settings.php if file not exist in your theme then you can create new file with the name theme-settings.php and write the following code in it:

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

    $default_file_dir_path = 'public://YOUR_DESIRE_DIRECTORY';
    $true = file_prepare_directory( $default_file_dir_path, FILE_CREATE_DIRECTORY);
    if($true==1){
        $form['your_file_field'] = array(
            '#type'          => 'managed_file',
            '#title'         => t('YOUR_TITLE'),
            '#default_value' => theme_get_setting('your_file_field'),
            '#progress_message' => t('Please wait...'),
            '#progress_indicator' => 'bar',
            '#upload_location' => 'public://YOUR_DESIRE_DIRECTORY',
            '#description'   => t("Upload your image."),
            '#upload_validators' => array(
                'file_validate_extensions' => array('gif png jpg jpeg'), 
                ),
            );
    }
}

If theme-settings.php file is not exist in your then write simple form submit button and submit function (if you require extra things) as per your requirement.

Use output of theme_get_settings for image :

$fid = theme_get_setting('your_file_field');
$image_url = file_create_url(file_load($fid)->uri);

You will get the image url in $image_url variable.

Thanks,
-Kamlesh