Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to access the following shortcode in a simple page, with [featured/]

function mytheme_featured() {
$my_query2 = new WP_Query('category_name=featured&showposts=1');
while ($my_query2->have_posts()) : $my_query2->the_post(); 
return '<h3 class="entry-title"><a href="'.the_permalink().'" title="Permalink to '.the_title_attribute( 'echo=0' ).'" rel="bookmark">'.the_title().'</a></h3><div class="entry-content">'.the_excerpt().'</div>';
endwhile;
}
add_shortcode( 'featured', 'mytheme_featured' );

However, the content of that post is displayed at the top of the page, instead of the location given to the shortocde, which is below the first paragraph, inside the box with the red border. Any thoughs on why this happens?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

the_title(), the_excerpt() and the_permalink() prints the output at once but the shortcode function is supposed to just return the output. You can use get_the_title(), get_permalink() and get_the_excerpt() instead.

share|improve this answer
    
Thank you so much! –  Andrew Apr 20 '12 at 12:04
add comment

Your Answer

 
discard

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.