The class implementing the block showing the theme logo, in SystemBrandingBlock::build()
contains the following code.
$build['site_logo'] = array(
'#theme' => 'image',
'#uri' => theme_get_setting('logo.url'),
'#alt' => $this->t('Home'),
'#access' => $this->configuration['use_site_logo'],
);
So, for the path of the logo, you can simply use theme_get_setting('logo.url')
, which returns "/core/themes/bartik/logo.svg"
, in my test site.
If you want a relative URL for the logo file, for example because you want to use it for the src
attribute of the <img>
tag, you can do as template_preprocess_image()
does.
$relative_url = file_url_transform_relative(file_create_url(theme_get_setting('logo.url')));
For an absolute URL, you can use the following code.
$absolute_url = file_create_url(theme_get_setting('logo.url'));
That code needs to go in a preprocess function, where it initializes a variable. For example, if I wanted the relative URL of the logo file in html.html.twig, I would use the following code.
function mytheme_preprocess_html(&$variables) {
$variables['relative_logo_url'] = file_url_transform_relative(file_create_url(theme_get_setting('logo.url')));
}
And in the template, you would just use {{ relative_logo_url }}
to get it.