Display total published words in “Right Now” admin dashboard

Adding this snippet to the functions.php of your wordpress theme will display the total number of published words from posts and pages. This is displayed at the bottom of the "Right Now" box in your wordpress admin dashboard.

( example screenshot )

Code Snippet:

function post_word_count() {
$count = 0;
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => array( 'post', 'page' )
foreach( $posts as $post ) {
$count += str_word_count( strip_tags( get_post_field( 'post_content', $post->ID )));
$num = number_format_i18n( $count );
$text = _n( 'Word', 'Words', $num );
echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>";
add_action( 'right_now_content_table_end', 'post_word_count');

Comments  Leave a Reply

  1. Can you show us how to display how many media images are in the libary in right now too please 🙁 i tried mixing both snipps on this website and broke my website at least 6 times. Please help 🙂

  2. Thanks Kevin, now works very well, thank you for this code, it help me.

    1. No problem Andre glad that I could help,

  3. Hi Kevin, I don’t understand what is the last line, I’ve this situation:

    // Create a custom widget function welcome() { echo ‘…………….’; } function register_widgets(){ wp_add_dashboard_widget(‘dashboard_widget’, ‘Hello’, ‘welcome’); } add_action(‘wp_dashboard_setup’, ‘register_widgets’);

    1. Hi Andre23, I posted something that should work for you, this will add the word count within a custom dashboard widget. http://pastebin.com/hDnereaS

      Just copy and paste within the function.php

  4. Kevin, if I want to display the words in a custom widgets, how can I do?

    1. Hi Andre23 well the reason this snippet puts the information within “right now” is because of the add_action. eg

      add_action( ‘right_now_content_table_end’, ‘post_word_count’);

      So if you remove that last line you could write your widget and call the same function to display within your widget. You will want to update the html so that it will work with your widget,

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!