Permalinking Featured Image using PHP
-
I am making a theme and want to have the featured image link to the post. Currently, I have it so if there is a featured image it will display it. If not, it will display nothing (as shown below).
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { // the current post lacks a thumbnail } ?>
I do not want to put a link around this code and have it display a link when there is no image. How can I do it so if there is a thumbnail then it will permalink the image. I tried this code but it doesn’t work:
<?php if ( has_post_thumbnail() ) { echo '<a href="'.the_permalink().'">'.the_post_thumbnail().'</a>'; } else { // the current post lacks a thumbnail } ?>
Instead it shows the link in plain text besides the image.
PS: I am not very good with PHP.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Permalinking Featured Image using PHP’ is closed to new replies.