the_custom_logo()
displays a custom logo image, linked to home, so you don’t need to echo it, wrap it inside a
tag or use it as a src
for an image.
If you want to use the default output, then just use in your theme file. If there’s no custom logo set, then the function results in an empty string i.e. nothing is displayed.
For custom output, first get the custom logo image ID with get_theme_mod( 'custom_logo' )
and then get the image markup with wp_get_attachment_image()
. Or the logo image url with wp_get_attachment_url()
or wp_get_attachment_image_src
.
Example with fallback, modified from how get_custom_logo()
works.
$custom_logo_id = get_theme_mod( 'custom_logo' );
if ( $custom_logo_id ) {
$custom_logo_attr = array(
'class' => 'custom-logo',
);
printf(
'<a href="https://wordpress.stackexchange.com/questions/355609/%1$s" class="custom-logo-link" rel="home">%2$s</a>',
esc_url( home_url( "https://wordpress.stackexchange.com/" ) ),
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );
);
} else {
$custom_logo_attr = array(
'class' => 'fallback-logo',
);
printf(
'<a href="https://wordpress.stackexchange.com/questions/355609/%1$s" class="custom-logo-link" rel="home">%2$s</a>',
esc_url( home_url( "https://wordpress.stackexchange.com/" ) ),
get_template_directory_uri() . '/assets/images/logo.png'
);
}