skip to Main Content

I am using the following code to display the thumbnail image named th-mag2 :

<img src="<?php echo the_post_thumbnail('th-mag2'); ?>" width="100%" class="object-fit card-img-top" height="150px" alt="img-news" loading="lazy">

But when it is displayed on the site, it is displayed as follows:

enter image description here

Please help me ….
thanks

2

Answers


  1. I am not an expert but the issue looks familiar to me. So I am trying to help you.

    <img src="<?php echo the_post_thumbnail('th-mag2'); ?>/images/th-mag2.jpg" width="100%" class="object-fit card-img-top" height="150px" alt="img-news" loading="lazy"/>
    

    You can try this one with .jpeg as well instead of .jpg if that’s your image extension.

    You can also try this one if the first one doesn’t work (with the correct image extension):

    <img src="<?php echo the_post_thumbnail(); ?>/images/th-mag2.jpg" width="100%" class="object-fit card-img-top" height="150px" alt="img-news" loading="lazy"/>
    
    Login or Signup to reply.
  2. if you want the Post Thumbnail URL only then you can not use the_post_thumbnail() function, it will print the complete Image Structure with Image tag also,

    So what you actually need to do is

    <?php the_post_thumbnail('th-mag2'); ?> 
    
    Instead of 
    
    <img src="<?php echo the_post_thumbnail('th-mag2'); ?>" width="100%" class="object-fit card-img-top" height="150px" alt="img-news" loading="lazy">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search