I am trying to add featured images while creating post. When user clicks on image it should get redirect to some external URL. I set custom field for redirect URL while creating post. But where to add the code in php file for redirection. While searching I found code
try and locate the line with the_post_thumbnail() in page.php, and add the link there;
example:
from:
<?php the_post_thumbnail(); ?>
to:
<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<a href="<?php echo $name; ?>"><?php the_post_thumbnail(); ?></a>
<?php } else {
the_post_thumbnail();
} ?>
But I didnt found <?php the_post_thumbnail(); ?> in page.php or single.php . Is it right approach or any other alternative ?