2

I am trying to get the post thumbnail to show in line with these other functions and am having no luck:

Info:

<?php echo '<h2><a href=\"' . get_permalink($attractions->post->ID) . '\">' . get_the_title($attractions->post->ID) . '</a></h2>' . get_the_post_thumbnail($attractions->post->ID, 'full') ;?>

I have tried all variations from Googling for an hour and cannot figure this out.

Any suggestions would be great.

1
  • re: 'get the post thumbnail to show in line' - are you referring to the formatting of the output? do you get the thumbnail to show at all? does the post actually have a featured image?
    – Michael
    Feb 27, 2015 at 10:10

1 Answer 1

4

If you are using this inside the loop of your WP_Query then why are you providing the Post ID parameter in functions. You don't need to do that.

So your code will become this.

<?php echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>' . get_the_post_thumbnail( get_the_ID(), 'full' ); ?>

And please read the answer and explanation by @PieterGoosen. He well explained how WordPress functions usually works. And how can you echo the results with get_ prefix.

Also you were using \ before double quote which you don't need to do here.

3
  • Not sure why you're suggesting OP use the 'full' parameter with get_the_post_thumbnail().
    – Jim Fell
    Mar 6, 2017 at 20:08
  • @JimFell Because the OP was using 'full' parameter in his code.
    – Robert hue
    Mar 8, 2017 at 21:20
  • @JimFell, you have to use 2 parameters if you want to specify the thumbnail size, which are the ID and the size (I edited the post above to reflect this). If you are OK with the default thumbnail, then simply get_the_post_thumbnail() is sufficient. But you can't call get_the_post_thumbnail( 'full' ) -- it won't work properly.
    – magi182
    Mar 22, 2017 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.