Create most recent posts dashboard widget

Adding this snippet to the functions.php of your wordpress theme will create a new dashboard widget showing the five most recent posts.

function wps_recent_posts_dw() {
          global $post;
          $args = array( 'numberposts' => 5 );

          $myposts = get_posts( $args );
		foreach( $myposts as $post ) :  setup_postdata($post); ?>
		    <li> (<? the_date('Y / n / d'); ?>) <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
	  <?php endforeach; ?>

function add_wps_recent_posts_dw() {
       wp_add_dashboard_widget( 'wps_recent_posts_dw', __( 'Recent Posts' ), 'wps_recent_posts_dw' );
add_action('wp_dashboard_setup', 'add_wps_recent_posts_dw' );

Comments  Leave a Reply

  1. add to category: dashboard

  2. this is what i’m looking for,

    thank you

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!