Feb
12
2011

How to Add Custom Post Types to Your WordPress Dashboard (in the Right Now Widget)

Blue Wordpress Logo with WordPress Text Thumbnail

If you use custom post types on your WordPress site, you may notice they don’t show up in the Right Now Widget when you view your Dashboard. The Right Now Widget is the area that includes counts for your other content such as Posts, Pages, Categories, and Tags. I like seeing this information as a quick summary of the content on my site, but it just doesn’t feel complete without custom post types counts included. So I decided to figure out how I could see counts for my custom post types as well. After doing some research, I came across a simple solution to do just that.

Adding Custom Post Types to Your WordPress Dashboard

To add all custom post types to your WordPress Dashboard, first backup your functions.php file. Now, open up functions.php and add the following code to it:

// Add all custom post types to the "Right Now" box on the Dashboard
add_action( 'right_now_content_table_end' , 'ucc_right_now_content_table_end' );

function ucc_right_now_content_table_end() {
  $args = array(
    'public' => true ,
    '_builtin' => false
  );
  $output = 'object';
  $operator = 'and';

  $post_types = get_post_types( $args , $output , $operator );

  foreach( $post_types as $post_type ) {
    $num_posts = wp_count_posts( $post_type->name );
    $num = number_format_i18n( $num_posts->publish );
    $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
    if ( current_user_can( 'edit_posts' ) ) {
      $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
      $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
    }
    echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
    echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
  }

}

This code comes from WordPress’s internal dashboard code, which was slightly modified to pull in custom post types (thanks to J.M. Dodd for posting this modification on Bajada.net).

Adding Taxonomies to Your WordPress Dashboard

If you want to also add custom taxonomies to the dashboard, you can also include this code inside the function “ucc_right_now_content_table_end()”:

$taxonomies = get_taxonomies( $args , $output , $operator );

  foreach( $taxonomies as $taxonomy ) {
    $num_terms  = wp_count_terms( $taxonomy->name );
    $num = number_format_i18n( $num_terms );
    $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ) );
    if ( current_user_can( 'manage_categories' ) ) {
      $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
      $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
    }
    echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
    echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
  }

That’s alll there is to it! Now, when you view your WordPress dashboard you’ll see counts for your custom post types and taxonomies!

About the Author: Dana Duncan

Hi, my name is Dana, and I've been building websites for over 12 years. It's a topic I'm passionate about and enjoy teaching. Here at All Webmaster.com I teach people how to create and run websites, and show businesses how to build or improve their web presence.

4 Comments + Add Comment

  • Thanks for the post. This is exactly what I was looking to accomplish.

    • No problem, glad it helped!

  • Awesome! I’m going to use this in my Sermon Manager plugin that I’m preparing right now!

    • Hi Jack, good to hear you found this wordpress tutorial helpful. It sounds like you’re putting together quite the package of wordpress themes, plugins and tutorials for your new site. I’ll be interested to see the final product once you release it. Stop by again and let me know once it’s finished. Some of my readers would probably like to hear about it as well, so maybe you’ll be interested in writing a guest post here once you’re done with development (I know how time consuming coding can be!)

Leave a comment

Welcome to All Webmaster!

Dana Duncan About Picture

Hi, my name is Dana and here at All Webmaster I teach people how to build websites. I've been creating websites professionally for over 12 years and this is where I'll share the things I've learned so you can build your own website and get people to visit it. [More about...]

Like Us on Facebook: