Skip to content
WJunction - Webmaster Forum

WordPress How to set a link to the_post_thumbnail?

Status
Not open for further replies.

Divvy

Experienced Member
806
2009
18
Hello guys,


I'm trying to insert link to my thumbnail images, but I'm stuck, can someone please help me?


My code is:


PHP:
<?php if(has_post_thumbnail()) :the_post_thumbnail( 'full' );else : ?>

Thank you for help!


Kind regards

-----------------------
After reading this url:
https://codex.wordpress.org/Function_Reference/the_post_thumbnail

I notice this solution:
PHP:
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>

But my php knowledge is very very poor, and I dont know how can I edit my code:

PHP:
<?php if(has_post_thumbnail()) :
the_post_thumbnail( 'full' );
else : ?>

As I can see, I need to put the_post_thumbnail( 'full' ); inside the a tag, but how? Any ideas? :)

Thanks!
 
Last edited:

5 comments

Replace
PHP:
<?php if(has_post_thumbnail()) :the_post_thumbnail( 'full' );else : ?>

with

PHP:
<?php if ( has_post_thumbnail() ) : ?> 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
<?php the_post_thumbnail('full'); ?> 
</a> 
<?php endif; ?>
 
Thank you for your replies :)

DejaVu, and where I put the else?

This is my full code:

PHP:
<?php if(has_post_thumbnail()) :
the_post_thumbnail( 'full' );
else : ?>
<img class="attachment-full wp-post-image" src="<?php bloginfo('template_url'); ?>/images/sample450.jpg" />
<?php endif; ?>

Thanks once again
 
Last edited:
PHP:
<?php if ( has_post_thumbnail() ) { ?> 
  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
  <?php the_post_thumbnail('full'); ?> 
  </a> 
<?php } else { ?>
  // else code here
<?php } ?>
 
Status
Not open for further replies.

About the author

D
Experienced Member · Joined
806
Messages
18
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom