sinanisler logo

Calculate all WordPress Posts How Many Words there are

add this to your functions.php and it will add Word Count named page to the dashboard and it will show the total word count for all posts.


// Add a custom page to the WordPress admin menu
function word_count_admin_menu() {
        'Word Count',
        'Word Count',
add_action('admin_menu', 'word_count_admin_menu');

// Display the total word count of all posts in the custom admin page
function word_count_admin_page() {
    global $wpdb;
    $total_word_count = 0;
    $results = $wpdb->get_results("SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'");

    foreach ($results as $result) {
        $word_count = str_word_count(strip_tags($result->post_content));
        $total_word_count += $word_count;
    <div class="wrap">
        <h1>Total Word Count</h1>
        <p>The total number of words in all posts: <?php echo esc_html($total_word_count); ?></p>


Leave the first comment