⏲️ Estimated reading time: 4 min
WordPress HelpZone give you all about the code we created for showing and sorting Word Count in the admin dashboard.
Add Column with Sorting to WordPress Admin. Learn how to display the words counting for each post in your WordPress admin dashboard, along with the ability to sort posts by words counting in ascending or descending order.
Display and Sort Word Count in WordPress Admin Dashboard
WordPress by default doesn’t show words counting in the admin panel which can be frustrating for bloggers, content managers, or SEO experts who care about content length. In this guide, we’ll show you how to add a custom words counting column to the Posts list in the dashboard, complete with sorting functionality.
You’ll also learn how to store the words counting as custom meta data, and bulk-update existing posts to populate the words counting without needing to manually resave them.

Why Add Word Count to the Admin Dashboard?
While the WordPress editor shows the words counting when editing a post, it’s not visible at a glance when managing multiple posts. With a custom column in the post list, you can:
- Monitor post length quickly.
- Sort long-form and short-form posts.
- Improve SEO and content planning.
- Identify thin content or overly long articles.
Full Code to Add Word Count Column and Enable Sorting
Below is a complete snippet you can place in your functions.php
file or in a custom plugin:
// Add Word Count Column
add_filter('manage_posts_columns', 'add_word_count_column');
function add_word_count_column($columns) {
$columns['word_count'] = 'Word Count';
return $columns;
}
// Display Word Count
add_action('manage_posts_custom_column', 'display_word_count_column', 10, 2);
function display_word_count_column($column_name, $post_id) {
if ($column_name === 'word_count') {
$word_count = get_post_meta($post_id, '_custom_word_count', true);
if (!$word_count) {
$content = get_post_field('post_content', $post_id);
$word_count = str_word_count(strip_tags($content));
update_post_meta($post_id, '_custom_word_count', $word_count);
}
echo $word_count;
}
}
// Make the column sortable
add_filter('manage_edit-post_sortable_columns', 'make_word_count_sortable');
function make_word_count_sortable($columns) {
$columns['word_count'] = 'word_count';
return $columns;
}
// Sorting logic
add_action('pre_get_posts', 'sort_posts_by_word_count');
function sort_posts_by_word_count($query) {
if (is_admin() && $query->is_main_query() && $query->get('orderby') === 'word_count') {
$query->set('meta_key', '_custom_word_count');
$query->set('orderby', 'meta_value_num');
}
}
// Save word count on post save
add_action('save_post', 'save_word_count_meta');
function save_word_count_meta($post_id) {
if (wp_is_post_revision($post_id) || get_post_type($post_id) !== 'post') return;
$content = get_post_field('post_content', $post_id);
$word_count = str_word_count(strip_tags($content));
update_post_meta($post_id, '_custom_word_count', $word_count);
}
// Admin notice for bulk update
add_action('admin_notices', 'word_count_bulk_update_notice');
function word_count_bulk_update_notice() {
if (isset($_GET['word_count_update']) && current_user_can('manage_options')) {
word_count_bulk_update();
echo '<div class="notice notice-success is-dismissible"><p>Word counts updated for all published posts.</p></div>';
} else {
echo '<div class="notice notice-info is-dismissible"><p><a href="' . admin_url('edit.php?word_count_update=1') . '" class="button">Update Word Count for All Posts</a></p></div>';
}
}
// Bulk update word count for existing posts
function word_count_bulk_update() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids'
);
$posts = get_posts($args);
foreach ($posts as $post_id) {
$content = get_post_field('post_content', $post_id);
$word_count = str_word_count(strip_tags($content));
update_post_meta($post_id, '_custom_word_count', $word_count);
}
}
How to Use It
- Paste the code into your
functions.php
file. - Go to Posts > All Posts in your admin dashboard.
- Click the blue button labeled “Update Word Count for All Posts.”
- You’ll now see a sortable “Word Count” column.
That’s it! You’ve just extended the WordPress dashboard with a powerful new tool.
🏷️ Tags: wordpress tutorial, wordpress admin, custom column, words counting, sortable posts, functions.php, wordpress developer, seo tools, wp backend, wordpress tips
Only logged-in users can submit reports.
Discover more from HelpZone
Subscribe to get the latest posts sent to your email.