Reputation: 29
I'm trying to amend a Wordpress template so that the thumbnail of a single post links to an external url. I have collected the url in a custom field (report_link).
I've tried a bunch of combinations of dots and apostrophes and speech quotes, but I think I must be missing something fundamental.
<?php
if ( has_post_thumbnail() ) {
$replink=the_field('report_link');
if( $thumbnail = get_the_post_thumbnail( null, 'slider', array( 'class' => 'img-fluid' ) ) ){
echo "<a href='$replink'>$thumbnail</a>";
}
}
?>
When I try to use $replink in the href the link on the thumbnail is back to the same post's url.
I also tried:
echo '<a href="'.$replink.'" target="_blank">Click</a>';
This returned the url in $replink printed to the screen and then a the word 'Click' which was linked back to the post page containing the link.
Upvotes: 0
Views: 230
Reputation: 56
You can make use of below function to make it work.
if ( has_post_thumbnail() ) {
$replink = get_field('report_link');
if( $thumbnail = get_the_post_thumbnail( null, 'slider', array( 'class' => 'img-fluid' ) ) ){
echo "<a href='".$replink."'>".$thumbnail."</a>";
}
}
Upvotes: 1