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

php - How to add Wordpress Featured image in <a> tag ..?

programmeradmin0浏览0评论

I am trying to add Wordpress featured image in tag. I used these 3 shortcodes.

<?php echo $image_large[0]; ?>
<?php echo get_the_post_thumbnail(null,'thumbnail');?>
<?php echo get_the_post_thumbnail( $page->ID, 'full' ); ?>

Example

<a href="<?php echo get_the_post_thumbnail( $page->ID, 'full' ); ?>" >View Larger</a>

But nothing working. Please help me ...

I am trying to add Wordpress featured image in tag. I used these 3 shortcodes.

<?php echo $image_large[0]; ?>
<?php echo get_the_post_thumbnail(null,'thumbnail');?>
<?php echo get_the_post_thumbnail( $page->ID, 'full' ); ?>

Example

<a href="<?php echo get_the_post_thumbnail( $page->ID, 'full' ); ?>" >View Larger</a>

But nothing working. Please help me ...

Share Improve this question edited Feb 24, 2020 at 2:37 user2996362 asked Feb 21, 2020 at 18:09 user2996362user2996362 32 bronze badges 1
  • You should call this method inside the loop, but your code is totally incomplete. Could you please add more information? – Cadu De Castro Alves Commented Feb 21, 2020 at 18:14
Add a comment  | 

2 Answers 2

Reset to default 0

It's not working because you're trying to echo the image into the href. What you want is just the URL to go there.

<?php echo get_the_post_thumbnail_url( $page->ID, 'full' )?>

You can learn more about this function here in the codex.

I hope that I understood your question correctly. You can try this.

    <?php if (has_post_thumbnail()): ?>
         <figure class="entry-thumb">
           <a href="<?php the_permalink();?>"tabindex="-1" aria-hidden="true">
             <?php the_post_thumbnail('full', ['alt' => esc_html (get_the_title())]); ?>
           </a>
        </figure>
   <?php endif; ?>
发布评论

评论列表(0)

  1. 暂无评论