0

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?

0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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