X

Post word count

Adding this PHP code to the functions.php of your wordpress theme adds a count of total published words to the bottom of the "Right Now" box on the admin dashboard.



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 );
// This block will add your word count to the stats portion of the Right Now box
$text = _n( 'Word', 'Words', $num );
echo "<tr><td class='first b'>{$num}</td><td class='t'>{$text}</td></tr>";
// This line will add your word count to the bottom of the Right Now box.
echo '<p>This blog contains a total of <strong>' . $num . '</strong> published words!</p>';
}

// add to Content Stats table
add_action( 'right_now_content_table_end', 'post_word_count');
// add to bottom of Activity Box
add_action('activity_box_end', 'post_word_count');

Comments  Leave a Reply

  1. Is it possible to add this to the actual blog with a template tag?

    1. Hi Justin yes you can do that, should be able to just add to your template file and this will be displayed. Keep in mind this script adds HTML you will want to change for this to work in your theme nicely.

  2. Tweets that mention Wordpress Post word count – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com January 4, 2011 at 12:48 am

    […] This post was mentioned on Twitter by Michael Davis, WPSNIPP. WPSNIPP said: #wordpress Post word count http://bit.ly/gULp1N #blog please RT 🙂 […]

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!