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

Currently I'm using this shortcode within a post


which works great, but somehow I can't add any text in front of this shortcode, without posting it the other way around.

In example

some dummy text [etalage]

will always be shown as

[etalage] some dummy text

I've read to gather the value into a variable and return it, but I have to admit, I'm not entirely sure how to accomplish this best

share|improve this question
up vote 3 down vote accepted

Here's your updated shortcode function which puts output in a variable and returns it. Note that you have to use functions that return data rather than output directly, in this case get_the_post_thumbnail() is used in place of the_post_thumbnail()

function cor_etalage_add_shortcode() {
    $output = '<div id="etalage"><ul>';

    $the_query = new WP_Query(array(
        'post_type' => array(

    while ($the_query->have_posts()) : $the_query->the_post();
        $output .= '<li>'. get_the_post_thumbnail($post->ID,'etalage') .'</li>';
    $output .= '</ul></div>';

    return $output;
add_shortcode('etalage', 'cor_etalage_add_shortcode');

EDIT oops, forgot to pass the post ID with get_the_post_thumbnail, updated.

share|improve this answer
Thanks, Milo, It completely answered my question and more! (it seems I can't edit your reply, but I've added an extra $ before output .= '</ul></div>';) – Cor van Noorloos Jun 6 '11 at 20:07
@Cor van Noorloos - ah, thanks, missed that! I've updated the answer to fix it. – Milo Jun 6 '11 at 20:12

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.