WordPress latest post shortcode for WYSIWYG Editor

Ever needed to show a link to the latest post dynamically in the text editor in WordPress?

Shortcodes are great little tools and easy to create, firstly you need to load up your themes functions page and add the following code.


function my_recent_posts_shortcode(){


$wp_query = null;
$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$latest = get_permalink();

return $latest;

add_shortcode(‘recent-news’, ‘my_recent_posts_shortcode’);

What you will see if your shrewd is the WordPress query code, the arguments to specify 1 post and in particular a category filter! Yes folks you get that bit for free! If you want to to just show the latest from a category use category_name=new. Now in your wordpress editor just drop in the tag


As they used to say in the olden days,