1

When adding a logo file to a custom theme, I can either

  1. save my logo in the theme folder as logo.png (replacing the default logo.png from the theme starterkit I'm using), or
  2. save my logo in the theme's images folder, using the filename I choose, and use the theme settings page at admin/appearance/settings/themename to set the logo path.

I'm looking for a way to save the logo file in the images folder, while setting the logo path programmatically. This would make sure that the logo is automatically set when enabling the theme. Wouldn't it make sense if that could be done in themename.info, using something like settings[logo_path] = path/to/my/logo-image.png?

3

In Drupal 6, I believe what you are looking for is

variable_set('logo_path', '/path');

At first glance though, I'm wondering why there is only one such on my site, and not one per theme. theme_get_settings appears to be grabbing defaults first, and then merging in theme specific settings on top of that.

In D7, the variable is called 'theme_themename_settings'.

  • I guess you mean variable_set('logo_path', '/path'). However looking at the variables table, there is no logo_path variable (using D7). The logo_path value is stored in a serialized array that can be retrieved with variable_get('theme_themename_settings', array()). Anyway, Suppose that you can set the value using variable_set, how would you make sure it runs when enabling a theme? – marcvangend Jan 4 '12 at 14:15
  • Yes, my mistake. On my site there is such a variable, but I happened to be sitting by a D6 site when I answered the question. I have updated the answer. – Letharion Jan 4 '12 at 15:30
  • Reacting programmatically on theme activation however, seems like more of a challenge... – Letharion Jan 4 '12 at 15:56
0

The above answer is incorrect for Drupal 6. The variable for the logo path in 6 is the same as the one listed for 7, namely theme_<theme name>_settings and the logo path has the key logo_path, so for Garland, the logo path would be in theme_garland_settings['logo_path']. There is also a flag for whether the theme uses the default logo or not, which should also be set. From PHP, you can accomplish this by:

$new_logo="path/to/logo";
$theme_name="theme_name";
$property="theme_" . $theme_name ."_settings";
$settings = variable_get($property, array()); 
$settings['logo_path'] = $new_logo; 
$settings['default_logo'] = 0; 
variable_set($property, $settings);

Or from a bash script using drush:

new_logo="path/to/logo"
theme_name="theme_name"
property="theme_${theme_name}_settings"
drush php-eval "\$settings = variable_get('${property}', array());     
\$settings['logo_path'] = '${new_logo}'; \$settings['default_logo'] = 0; 
variable_set('${property}',\$settings);"
0

For Drupal 7, in case you need to change the logo from configs.

$conf['theme_my_theme_settings'] = [
  'default_logo' => 0,
  'logo_path' => 'sites/my_theme/themes/mytheme/logo.png',
  'default_favicon' => 0,
  'favicon_path' => 'sites/my_theme/themes/mytheme/favicon.ico'
];
  • Thanks for your contribution Sergiu! – marcvangend Sep 5 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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