Open In App

How to add Word Count in the WordPress Dashboard ?

Last Updated : 25 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

WordPress is an open-source Content Management System that is based on PHP and MySql and is used to create a dynamic website. It was developed by Matt Mullenweg and Written in PHP. WordPress is one of the most popular that allows customizing and managing the website from its back-end content management system.

If you are using WordPress for blogging and have multiple authors contributing to your website, it is important to have word count statistics in your WordPress dashboard. This allows you to evaluate the content and ensure it meets the required word limits. In this article, we will explain how to add the word count feature to your WordPress dashboard. Let’s get started!

After installing and activating the plugin, the word count will be displayed in the “Post” section of the Dashboard for each post.

1. Word count using the WordPress plugin

Step 1: First login to your WordPress dashboard using the user login id and password.

 

Step 2: After login into your WordPress dashboard, now hover over the “Plugins” section and then click on the “Add New” button to add the plugin.

 

Step 3: Now search for “Word Count Analysis” in the search box and then click on the “Install Now” button to install the plugin on your WordPress website.

 

Step 4: After installing the plugin, click on the “Activate” button to activate the plugin on your WordPress website.

 

Step 5: After activating the plugin, now choose the language, we are choosing the English language and then clicking on the “Count and analyze words” button.

 

Step 6: Now it will start showing the word count in front of the posts.

This is how you add the word count stats to your WordPress website using the plugin.

Now let us see how we can add the word count stats using the code.

2. Adding word count using the custom code

  • This method is for experts who have some coding knowledge in the PHP programming language. 
  • You have to add the code to the “functions.php” file on your WordPress website.
  • The “functions.php” file is found in the theme folder. You can find the “functions.php” file in the path of “wp-content/themes/your-theme/functions.php”
  • Add the code given below and it will start showing the word count stats in your WordPress dashboard.
PHP
<?php

// Display the word count in the custom column
// Add custom column to the Posts list in 
// the dashboard
function word_count_column( $columns ) {
    $columns['word_count'] = 'Word Count';
    return $columns;
}

add_filter( 'manage_posts_columns', 'word_count_column' );

// Populate the custom column in the Posts list
function word_count_column_content( $column, $post_id ) {
    if ( 'word_count' === $column ) {
        $content = get_post_field( 'post_content', $post_id );
        $word_count = str_word_count( strip_tags( $content ) );
        echo $word_count;
    }
}

add_action( 'manage_posts_custom_column', 
    'word_count_column_content', 10, 2 );

?>

Now it will start showing the word count on your WordPress dashboard.

This is how you add the word count using the custom code to your WordPress website.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads