I have a custom logo and I have tried to get his path in this way theme_get_setting('logo_path')
, but no expected result.
I am using the code in a custom block, in input PHP.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communitylogo_path
seems to only be set if you override the theme's default logo via its theme settings. To get the default logo, use theme_get_setting('logo')
.
theme_get_setting('logo')
is empty string ? I have set my custom logo in /admin/appearance/setting
TOGGLE DISPLAY - Enable or disable the display of certain page elements.
the theme_get_setting('logo')
has no results. Why ?
<a href="<?php echo theme_get_setting('logo');?>">
in a PHP code block to show the logo in your own block.
global $base_url;
drupal_theme_initialize();
if (!$logo = theme_get_setting('logo_path')) {
$logo = theme_get_setting('logo');
}
if (!empty($logo)) {
// [1]
// Remove the base URL from the result returned by theme_get_setting('logo').
// If you don't need the relative path, you can remove this code.
if (strpos($logo, $base_url) === 0) {
$logo = drupal_substr($logo, drupal_strlen($base_url));
}
// [1]
// …
}
The call to drupal_theme_initialize() is not strictly necessary, and it doesn't do anything if the global variable $theme
is already initialized.
The code is removing the base URL because the value reported from theme_get_setting('logo')
is an absolute path; if you don't need a relative path to access the file, then the part between // [1]
can be removed.
When the logo has been disabled in the theme settings, theme_get_setting('logo')
doesn't return anything.
[1]
with $logo = file_create_url($logo);
in order to get the full URL path of the logo (with the http://).
Aug 5, 2014 at 10:15
theme_get_setting('logo_path', 'THEME_NAME')
, replacing THEME_NAME with the name of your theme?