get_custom_logo()
Gets the HTML code of the site logo set in the customizer (in the theme settings). The code will be: <a href="https://wp-kama.ru/"><img></a>.
To be able to set the logo in the customizer, you need to enable support for custom-logo in the theme: add_theme_support( 'custom-logo' ).
Use $custom_logo_id = get_theme_mod( 'custom_logo' ); to get the attachment ID of the logo, and then process it somehow differently...
Used By: the_custom_logo()
Hooks from the function
Returns
String. HTML code of the logo. The code will contain a link to the homepage and an IMG tag of the logo itself.
If the logo is not set in the theme settings, it will return an empty string.
Usage
get_custom_logo( $blog_id );
- $blog_id(number)
- ID of the site/blog whose logo needs to be retrieved.
Default: 0 (current blog)
Examples
#1 Get the site logo
Let's say we have enabled logo theme feature and we specified the image, then:
echo get_custom_logo(); /* Outputs such HTML code (but in one line): <a href="http://example.com/" class="custom-logo-link" rel="home" itemprop="url"> <img width="491" height="299" src="http://example.com/wp-content/uploads/2013/04/cropped-cropped-triforce-wallpaper.jpg" class="custom-logo" alt="cropped-cropped-triforce-wallpaper.jpg" itemprop="logo" srcset=" http://example.com/wp-content/uploads/2013/04/cropped-cropped-triforce-wallpaper.jpg 491w, http://example.com/wp-content/uploads/2013/04/cropped-cropped-triforce-wallpaper-300x183.jpg 300w" sizes="(max-width: 491px) 100vw, 491px" /> </a> */
#2 Check if a logo is specified for the site
$logo = get_custom_logo();
if( $logo ){
echo 'We have the logo;
} #3 Retrieve only the logo URL (link)
$custom_logo_id = get_theme_mod( 'custom_logo' ); $image = wp_get_attachment_image_src( $custom_logo_id , 'full' ); // display it: echo $image[0];
An alternative way to get the URL of the custom logo image:
echo esc_url( wp_get_attachment_url( get_theme_mod( 'custom_logo' ) ) );
Changelog
| Since 4.5.0 | Introduced. |
| Since 5.5.0 | Added option to remove the link on the home page with unlink-homepage-logo theme support for the custom-logo theme feature. |
| Since 5.5.1 | Disabled lazy-loading by default. |