How to add custom logo in WordPress theme

If you want to add Custom Logo in your wordpress theme. you can follow below steps.

1) Adding Custom Logo support to your Theme

To enable the use of a custom logo in your theme, add the following to your functions.php file:

add_theme_support( 'custom-logo' );

2) Displaying the custom logo in your theme

If you want to get your current logo. Open the file where you want the theme logo to appear.

<?php 
$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo = wp_get_attachment_image_src( $custom_logo_id, 'full' );
	if ( has_custom_logo() ) {
	 	echo '<img class="img-fluid" src="' . esc_url( $logo[0] ) . '" alt="'. get_bloginfo( 'name' ) .'">';
	 } else {
	 	echo '<h1>' . get_bloginfo( 'name' ) . '</h1>';
	 }
?>

3) Setup custom logo in your dashboard

  1. login your WordPress dashboard, go to Appearances, and then Customize.
  2. Click on Site Identity.
  3. You can see Upload/Change the logo option. (this is also where you can can upload a favicon — Site Icon). then choose your logo from media
  4. Click on the Save & Publish button in the top of the side bar.
  5. Refresh the page and there it is!

Leave a Reply

Your email address will not be published. Required fields are marked *