0
votes

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 ?

1

1 Answers

0
votes

If you are using the default template then location the content.php file in your theme directory which serve the blog data to index.php file for display blog content.

<?php get_template_part( 'content', get_post_format() ); ?>

This means your content.php file according to twentytwelve template. Hope this help you.