Drupal - How do I get the logo path?

logo_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').


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.

Tags:

Media

7