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'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>';
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
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

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.