WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this is shortcode in template:

function shortcode_frame_left( $atts, $content = null)

   return '<span class="frame alignleft">'. do_shortcode($content) . '</span>';
add_shortcode('frame_left', 'shortcode_frame_left');

this is how using in post content:

[frame_left] <a href="YOUR-URL"><img src="YOUR-URL" /></a> [/frame_left]

I am trying to use this shortcode in template file for displaying post thumbnails. What i try:

if (has_post_thumbnail()) {

apply_filters( 'the_content', "[frame_left]".the_post_thumbnail()."[/frame_left]"); 


if (has_post_thumbnail()) {

$thumbnail = '[frame_left]'. the_post_thumbnail() . '[/frame_left]';
echo do_shortcode("$thumbnail");


What am i doing wrong?

share|improve this question
Your shortcode definition is frame_left, code examples use frame_right. Can I assume you have frame_right shortcode defined in same way? – Rarst Nov 15 '10 at 7:18
OH so sorry, that was example, i copy wrong shortcode seems, template have both frame_left and frame_right btw. – Ünsal Korkmaz Nov 15 '10 at 14:53
@Ünsal: You don't have to edit your question to include the answer, that will confuse future readers. Just leave it as it was, so people with a similar problem can find the question and the given answer(s). I recommend you edit it and the rollback to the previous revision. – Jan Fabry Nov 15 '10 at 17:02
up vote 4 down vote accepted

the_post_thumbnail() echos the thumbnail and returns nothing. You probably want to use get_the_post_thumbnail() which returns it as a string. Your code currently is equivalent to this:

if (has_post_thumbnail()) {
    // Echo the thumbnail
    // Apply the filter but do nothing with the result.
    apply_filters( 'the_content', "[frame_left]"."[/frame_left]");

if (has_post_thumbnail()) {
    // Echo the thumbnail
    $thumbnail = '[frame_left]' . '[/frame_left]';
    // Echo the <span> with an empty content
    echo do_shortcode("$thumbnail");
share|improve this answer
not working.. for example your 2nd codes result is: <img src=""><span class="frame alignleft"></span>[/frame_left] – Ünsal Korkmaz Nov 15 '10 at 16:39
image is displaying but not inside of <span> and there is [/frame_left] which is weird – Ünsal Korkmaz Nov 15 '10 at 16:40
oh i got it.. you mean answer is if (has_post_thumbnail()) { // Echo the thumbnail $thumbnail = '[frame_right]' . get_the_post_thumbnail() . '[/frame_right]'; // Echo the <span> with an empty content echo do_shortcode("$thumbnail"); } – Ünsal Korkmaz Nov 15 '10 at 16:44
@Ünsal: Indeed, my example is not what you should do, but what your current code is doing. You should just use your current code, but replace the_post_thumbnail() with get_the_post_thumbnail() (and probably echo that apply_filters() result?). – Jan Fabry Nov 15 '10 at 16:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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