Hi Wippy,
I’d suggest rewriting the function to make each thing that you’re returning a discreet element to avoid this.
function post_thumbnail( $atts, $content = null ) {
$output = '<div id="post_thumbnail">';
$output .= the_post_thumbnail('thumbnail');
$output .= '</div>';
return $output;
}
add_shortcode("post_thumbnail", "post_thumbnail");
This should put the thumbnail back within your div.
the problem is the usage of the_post_thumbnail() function which echos the thumbnail image code;
use get_the_post_thumbnail() instead; (you might need to add the post id ?)
http://codex.ww.wp.xz.cn/Function_Reference/get_the_post_thumbnail
possibly also have a look at my related post:
http://www.transformationpowertools.com/wordpress/insert-featured-image-into-post-content-shortcode
code http://pastebin.com/6cQHzRjz
This happened because you are using the_post_thumbnail() which show the thumbnail image. For return statement you have to use get_the_post_thumbnail() instead of the_post_thumbnail();
function post_thumbnail( $atts, $content = null ) {
return '<div id="post_thumbnail">' . get_the_post_thumbnail('thumbnail') . '</div>';
}
add_shortcode("post_thumbnail", "post_thumbnail");
Good catch, I didn’t even notice the incorrect usage of the_post_thumbnail.
My recommendation can still stand if it is still loading out of the div, as you’re being more specific in where you want the code to go.
Thread Starter
wippy
(@wippy)
Hi, David Laietta.
Your function behave the same way like mine. Thank you, anyway.
Hi, alchymyth.
Your solution worked. Thank you.
Function:
function post_thumbnail( $atts, $content = null ) {
return '<div id="post_thumbnail">' . get_the_post_thumbnail($post_id, 'thumbnail') . '</div>';
}
add_shortcode("post_thumbnail", "post_thumbnail");
Thread Starter
wippy
(@wippy)
Hi, frizax.
You are fast. 😀
Well, your code just needs $post_id inside, I don’t know why, but without it inside, image will always show full size.