문제

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 ...

도움이 되었습니까?

해결책

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; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top