最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

images - HTML showing after PHP code in <img> tag

programmeradmin1浏览0评论

I am trying to display a page featured image. Every time I use the img tag,the text after the php code (" class="headshot" >) displays below the picture on the website. See picture screenshot of picture below

<div class="bio-picture">
    <img url="<?php the_post_thumbnail('full');?>" class="headshot">
</div>

I am trying to display a page featured image. Every time I use the img tag,the text after the php code (" class="headshot" >) displays below the picture on the website. See picture screenshot of picture below

<div class="bio-picture">
    <img url="<?php the_post_thumbnail('full');?>" class="headshot">
</div>
Share Improve this question asked May 9, 2020 at 1:47 nicannlnicannl 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

This is because the_post_thubmnail() outputs an <img> tag. So the result of your code will be something like this:

<div class="bio-picture">
    <img url="<img src="thumbnail/image/url.jpg" class="wp-post-image attachment-full">" class="headshot">
</div>

Your screenshot is how the browser has chosen to handle that broken HTML.

If you want to output the post thumbnail <img> with a custom class, use this:

<div class="bio-picture">
    <?php the_post_thumbnail( 'full', array( 'class' => 'headshot' ) );?>
</div>

Also, please note that the correct attribute for the img tag's URl is not url, it's src.

发布评论

评论列表(0)

  1. 暂无评论