X

Display Total Published Words in “Right Now” Admin Dashboard

Snippets by IsItWP

Do you want to display total number of published words from posts and pages in your admin dashboard? While there’s probably a plugin for this, we have created a quick code snippet that you can use display total published words in “Right Now” admin dashboard in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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');

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: How to create stunning WordPress optin forms and 7 best WordPress poll plugins to grow onsite engagement.

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!
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF TODAY!]
[50% OFF TODAY!]
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]