phantom phantom - 3 months ago 8
PHP Question

>" after image in wordpress php code

I am dynamically adding images to a post in wp using php. I am able to pull the post thumbnail image from the post by using

the_post_thumbnail();
function, however there is showing
">
after the image. I have tried to play around with the following line, but cannot get rid of the
">
.

<img src="<?php echo the_post_thumbnail();?>">


I have tried each way i could think of but cannot figure it out.

Please see complete code below the image.

enter image description here]1

<?php $query = new WP_Query( 'posts_per_page=5' ); ?>

<?php while ($query -> have_posts()) : $query -> the_post(); ?>

<div class="blog">
<img src="<?php echo the_post_thumbnail();?>">
</div>

Answer

Remove the img tag and just echo the_post_thumbnail(), this function already deals with the img tags. See here

<div class="blog">
    <?php echo the_post_thumbnail();?>
</div>
Comments