How To Display a Word Count Box in the WP Admin Dashboard

⏲️ Estimated reading time: 3 min


Add a custom widget to your WordPress admin dashboard that displays the total word count across all published posts. This PHP snippet is perfect for content-heavy websites and SEO monitoring.


📘 Display a Total Word Count Box in the WordPress Admin Dashboard

If you’re managing a content-heavy WordPress website, keeping track of the total number of words across your posts can be useful for SEO audits, content planning, and productivity tracking. In this guide, we’ll show you how to add a Total Word Count Box directly to your WordPress Admin Dashboard using a simple PHP function.


Display a Total Word Count Box in the WordPress Admin Dashboard

🧩 Why Add a Word Count Widget?

Knowing the total for your published content gives you insights into:

  • Your overall content volume
  • How much content is being produced over time
  • Content audit benchmarks
  • SEO optimization efforts

This is especially useful for multi-author blogs, agencies, and editorial teams.


🛠️ Step-by-Step: Add the Word Count Box with PHP

Follow these steps to insert a custom widget that counts all words from your published posts:

1. Open Your Theme’s functions.php File

Navigate to:
/wp-content/themes/your-theme/functions.php

Or use a code snippets plugin to insert the following code safely.

2. Insert This PHP Code

add_action('wp_dashboard_setup', 'hz_add_word_count_dashboard_widget');

function hz_add_word_count_dashboard_widget() {
    wp_add_dashboard_widget('hz_total_word_count', 'Total Word Count (All Posts)', 'hz_display_word_count_widget');
}

function hz_display_word_count_widget() {
    $total_words = 0;

    $all_posts = get_posts(array(
        'numberposts' => -1,
        'post_type'   => 'post',
        'post_status' => 'publish',
        'fields'      => 'ids'
    ));

    foreach ($all_posts as $post_id) {
        $content = get_post_field('post_content', $post_id);
        $word_count = str_word_count(strip_tags($content));
        $total_words += $word_count;
    }

    echo '<p><strong>Total Words:</strong> ' . number_format($total_words) . '</p>';
}

🖥️ Where Will the Widget Appear?

Once saved, go to Dashboard → Home in your WordPress admin area. You will see a box titled “Total Word Count (All Posts)”, displaying the number of words across all published posts.


🧪 Optional: Count Words from Pages or Custom Post Types

If you want to extend this to pages or custom post types, modify the 'post_type' => 'post' to an array like this:

'post_type' => array('post', 'page', 'your_custom_type'),

🚫 Don’t Forget Security and Performance

If you have thousands of posts, this could slow down your dashboard slightly. Consider caching the result with a transient if performance is affected.


📩 Do you have questions or suggestions? Leave a comment or contact us!
🏷️ Tags: WordPress Admin, Dashboard Widget, Word Count, WordPress Tips, PHP Snippets, functions.php, WordPress Development, SEO Tools, Blogging Tools, WP Admin Customization

Report an issue (max 5 words):

Only logged-in users can submit reports.


Discover more from HelpZone

Subscribe to get the latest posts sent to your email.

Want to support us? Let friends in on the secret and share your favorite post!

Photo of author

Flo

How To Display a Word Count Box in the WP Admin Dashboard

Published

Update

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! 🚀

👍 Like us on Facebook!

Closing in 10 seconds

Leave a Reply