Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Last active December 2, 2018 13:40
Show Gist options
  • Save huzaifaarain/dd02be3450cdcca1883c27759e4cb01f to your computer and use it in GitHub Desktop.
Save huzaifaarain/dd02be3450cdcca1883c27759e4cb01f to your computer and use it in GitHub Desktop.
Displaying the custom logo in your theme

Displaying the custom logo in your theme

A custom logo can be displayed in the theme using the_custom_logo() function. But it’s recommended to wrap the code in a function_exists() call to maintain backward compatibility with the older versions of WordPress, like this:

if ( function_exists( 'the_custom_logo' ) ) {
    the_custom_logo();
}

Generally logos are added to the header.php file of the theme, but it can be elsewhere as well.

If you want to get your current logo URL (or use your own markup) instead of the default markup, you can use the following code:

$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
if ( has_custom_logo() ) {
        echo '<img src="'. esc_url( $logo[0] ) .'">';
} else {
        echo '<h1>'. get_bloginfo( 'name' ) .'</h1>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment