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

I am trying to put several queries in a shortcode so that I can call them in a page instead of using custom templates. I got my query going but I only see some of the content on the page. The image shows up, the text shows up but none of the html markup is showing up. Is there a Wordpress function that I need to pass this all through so it doesn't strip the HTML?

function band_query($atts) { ?>
        "category" => '',
        "number" => ''
    ), $atts));

    $band = new WP_Query( array(
        'category_name' => $category,
        'posts_per_page' => $number
    $output = '';
    // The Loop
    if( $band->have_posts()):
        $output .= '<div id="band_bio">';
        $output .= '<ul>';
        while ( $band->have_posts() ) : $band->the_post(); 
            $output .= '<li>';
            $output .= '<figure>' . the_post_thumbnail('band', array('class' => 'left marg_right1')) .' </figure>';
            if ( has_excerpt()){
                $output .= the_excerpt();
            } else {
                $output .= the_content(); 
            $output .= '<div class="relative"><a href=' .the_permalink() . 'class="button1">  <span></span><strong>Read More</strong></a></div>';
            $output .= '</li>';
    $output .= '</ul>';

    $output .= '
    <a href="#" class="prev"></a>

    <a href="#" class="next"></a>

    $output = apply_filters('the_content', $content);   
    return $output;

add_shortcode("band_page", "band_query");
share|improve this question
You forgot a closing quote. Look at the output of the syntax highlighter. – toscho Apr 20 '13 at 22:52
And the first <ul> is outside of $output. Also, using a nice indentation in the code makes it easier to read and debug. – brasofilo Apr 21 '13 at 0:12
my syntax highlighter doesn't show a missing anything. I don't see one either. As far as the indenting. Is there a trick to getting it to work on this site? I do indent my code and then I have to spend 10 minutes trying to make it look readable here. Eventually, I get it close enough and post it. It loses all formatting when I copy it over – Jamie Apr 21 '13 at 3:15
up vote 4 down vote accepted

When you are constructing the $output variable, you need to consider


that return the values instead of


that echo the values.

share|improve this answer
Thank you for your reply. This helped a lot – Jamie Apr 21 '13 at 22:55

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.