has_custom_logo()
Checks if a logo is set for the site.
Works only if the theme supports custom-logo. Support is enabled via add_theme_support( 'custom-logo' ).
Convenient before calling the_custom_logo() to avoid getting an empty output.
Use get_theme_mod( 'custom_logo' ) to get the logo ID.
Uses: get_theme_mod()
1 time — 0.000037 sec (very fast) | 50000 times — 0.59 sec (very fast) | PHP 7.0.5, WP 4.5
No Hooks.
Returns
true|false
. Whether a logo is set or not.
Usage
if( has_custom_logo( $blog_id ) ){ // logo exists }
- $blog_id(int)
- ID of the site/blog for which to check the presence of a logo.
Default: 0 (current blog)
Examples
#1 Check if the logo is specified for the site
if( has_custom_logo() ){ // we have a logo, display it echo get_custom_logo(); }
#2 Using get_custom_logo()
Let's check if a logo is set for the site and immediately display it.
if( $logo = get_custom_logo() ){ echo $logo; }
See also:
Changelog
Since 4.5.0 | Introduced. |
has_custom_logo() has custom logo code WP 6.8.1
function has_custom_logo( $blog_id = 0 ) { $switched_blog = false; if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) { switch_to_blog( $blog_id ); $switched_blog = true; } $custom_logo_id = get_theme_mod( 'custom_logo' ); $is_image = ( $custom_logo_id ) ? wp_attachment_is_image( $custom_logo_id ) : false; if ( $switched_blog ) { restore_current_blog(); } return $is_image; }