Get Wordpress custom logo image URL or source for custom sizes.
WordPress theme can provide a built-in option to set custom logo image from the Customizer.
WP has following built-in functions related to getting a custom logo:
the_custom_logo()– prints the logo with markup
get_custom_logo()– prints the logo with markup considering the parameters
has_custom_logo()– checks whether the custom logo is set or not
Unfortunately, none of the functions above return only the URL of the custom logo image. Developers might need the URL of custom logo added by user, therefore, we will directly get the URL from
wp_get_attachment_image_src() function by padding custom logo id and the size of custom logo. If you don’t specify the size, it returns the URLs for all sizes of the custom logo.
wp_get_attachment_image_src() returns array. We’ll use
 to get the first required image.
$logo_original = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full');
get_theme_mod('custom_logo') function to get the ID of custom logo set via WordPress Customizer options.
To get custom logo in other available sizes, just replace
'full' with your custom image size such as thumbnail, medium, medium_large, large, and other registered custom image sizes.
Note: If the logo was set prior to the registration of custom sizes, then you need to remove and upload the logo again to let WP generate custom sizes for that logo image too.
$logo_other_size = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'thumbnail'); $logo_custom_size = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'another-registered-size');
Digital Setups has enforced a strict sourcing policy. Every content piece published on our website is passed through strict editorial review for contextual correctness, communication ethics, and programmatic tests wherever required. Our team research solutions from only credible, authentic, and trustworthy sources. Learn more about our editorial process.
Our standardized editorial process ensures right, timely, and healthy updates to our content. Your honest opinion drives significant improvement to our content. We appreciate you are taking time to share that.