Make logo dynamic in wordpress
-
05-05-2021 - |
Question
I have a problem with my wordpress site logo. I cannot make the site logo dynamic.
here is my code (displaying logo) which is in header.php page:
<a href="<?php echo get_home_url(); ?>" id="logo">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" class="img-responsive" alt="" title="">
</a>
***** when I want to change it from Customize > Site Identity, here it shows that no logo is attached, yet the logo is displaying successfully at front-end. Even when I try to change it, nothing happens.
Kindly help me to solve this issue.
Solution
Theme header logo function get_theme_mod( 'custom_logo' );
$custom_logo_id = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
echo '<img class="header_logo" src="'.$image[0].'">';
OTHER TIPS
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
Just change the 'full' to 'thumbnail' or something else. You can also define custom sizes. Or you could target it by the class 'header_logo' in css.
Use this code in header.php :
<img src="<?php header_image(); ?>" alt="">
Then open site wp-admin : Go to apperence -> customize -> Header Image and upload logo and publish it