最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Using concatenate with WordPress Thumbnail

matteradmin10PV0评论

Hi can someone explain me why the thumbnail is showing outside from the div? am i using the function correctly to concatenate the thumbnail inside the $list. BTW im running this code inside a shortcode that's why i use a concatenate function.

$list = "";
$list = " <div class='box'> ". the_post_thumbnail('post-thumbnail') . "</div>";

Hi can someone explain me why the thumbnail is showing outside from the div? am i using the function correctly to concatenate the thumbnail inside the $list. BTW im running this code inside a shortcode that's why i use a concatenate function.

$list = "";
$list = " <div class='box'> ". the_post_thumbnail('post-thumbnail') . "</div>";
Share Improve this question edited Dec 27, 2018 at 7:38 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 27, 2018 at 6:59 j. Redj. Red 133 bronze badges 1
  • Can you please share the output HTML you are getting for the above – Pratik bhatt Commented Dec 27, 2018 at 7:08
Add a comment  | 

1 Answer 1

Reset to default 2

the_post_thumbnail function echoes the result and does not return anything.

If you want to concatenate it this way, you should use wp_get_attachment_image instead.

$list .= '<div>'. wp_get_attachment_image( get_post_thumbnail_id(), 'post-thumbnail' ) . '</div>';

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far