WP: Get Custom Logo Image URL for Built-in or Custom Sizes
Get Wordpress custom logo image URL or source for custom sizes.
In adherence to our rigorous editorial policy, this article's content has undergone careful testing for accuracy and trustworthiness and hence, this content is marked source of information. View editorial history of this content.
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 markupget_custom_logo()
– prints the logo with markup considering the parametershas_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.
By default, wp_get_attachment_image_src()
returns array. We’ll use [0]
to get the first required image.
$logo_original = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'full')[0];
We used 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')[0];
$logo_custom_size = wp_get_attachment_image_src(get_theme_mod('custom_logo'), 'another-registered-size')[0];
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.
This article may have additional citations but they are not yet reviewed for trustworthiness. We will add them here at our earliest.
Based on our editorial policy, we update our content time to time to ensure its usefulness, reliability, and validity.
Our standardized editorial process ensures right, timely, and usefulness updates to our content. Your honest opinion drives significant improvement to our content. We appreciate you are taking time to share that.
Readers who read this also found these helpful:
- Authorship in SEO (2022)
- Block Editor: theme.json – Register Patterns
- WP: Add Support for Custom Logo in Theme
- Strange. Do you also see people dancing here and there?
- Does Hiding Actual Content with Captchas Impact SEO?
- Why my site webpages are not indexing properly in search results?
- How Dynamic Content Rendering via Edge Workers Impact SEO
- Apache Access Log Entry: CONNECT Method
- SafePay – Payment Gateway in Pakistan
- OPTIONS / RTSP/1.0″ – Apache Access Log Entry