I have created a shortcode to display the featured image linking to the post:

function ck13_post_image($atts){
      'ck_img_size'      => 'full'
   ), $atts));

    $show_the_image .= '<a href="' . get_permalink() . '">' . the_post_thumbnail("$ck_img_size") . '</a>'; 
    return $show_the_image;


function register_shortcodes(){
   add_shortcode('show-post-img', 'ck13_post_image');
add_action( 'init', 'register_shortcodes');

But instead of displaying the image inside the post, the image is displayed above it.

The weird thing is that the link to the post is displayed correctly inside the post, just the image is above.
Did i make some mistake? How can i make this work?

1 Answer 1


the_post_thumbnail echoes its value, which doesn't work in variable assignment. Use get_the_post_thumbnail instead.

Most WordPress API functions follow this pattern, there are typically two versions - one which will echo the result and another with get_ prepended which will return the result.

  • Yeah, my bad here, i tried get_the_post_thumbnail just without $page->ID. Thanks.
    – CK13
    Apr 28, 2014 at 18:05

Your Answer

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

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