Using WordPress ‘has_custom_logo()’ PHP function

The has_custom_logo() WordPress PHP function determines whether the site has a custom logo.

Usage

To check if a site has a custom logo:

if (has_custom_logo()) {
    // Site has a custom logo
} else {
    // Site doesn't have a custom logo
}

Parameters

  • $blog_id (int, optional) – ID of the blog in question. Default is the ID of the current blog.

More information

See WordPress Developer Resources: has_custom_logo

Related functions: the_custom_logo(), get_custom_logo()

To get the URL of the custom logo image:

$custom_logo_id = get_theme_mod('custom_logo');
$image = wp_get_attachment_image_src($custom_logo_id, 'full');
echo $image[0];

Examples

Display custom logo or site title

If the site has a custom logo, display it; otherwise, display the site title.

if (has_custom_logo()) {
    the_custom_logo();
} else {
    bloginfo('name');
}

Add a custom CSS class to the custom logo.

if (has_custom_logo()) {
    $custom_logo_id = get_theme_mod('custom_logo');
    $logo = wp_get_attachment_image_src($custom_logo_id, 'full');
    echo '<img src="' . esc_url($logo[0]) . '" class="custom-logo-class" alt="' . get_bloginfo('name') . '">';
}

Display custom logo with fallback image

Display the custom logo if available, otherwise use a fallback image.

if (has_custom_logo()) {
    the_custom_logo();
} else {
    echo '<img src="' . esc_url(get_template_directory_uri() . '/images/fallback-logo.png') . '" alt="' . get_bloginfo('name') . '">';
}

Display custom logo only on the homepage

Display the custom logo only on the homepage.

if (is_front_page() && has_custom_logo()) {
    the_custom_logo();
}

Display the custom logo wrapped in a link to the homepage.

if (has_custom_logo()) {
    $custom_logo_id = get_theme_mod('custom_logo');
    $logo = wp_get_attachment_image_src($custom_logo_id, 'full');
    echo '<a href="' . esc_url(home_url('/')) . '"><img src="' . esc_url($logo[0]) . '" alt="' . get_bloginfo('name') . '"></a>';
}