Add post content word count column to admin posts list in WordPress

add_filter( 'manage_edit-post_columns',        'add_words_column', PHP_INT_MAX );
add_action( 'manage_post_posts_custom_column', 'render_words_column', PHP_INT_MAX );
/**
 * add_words_column.
 */
function add_words_column( $columns ) {
	$columns['word_count'] = 'Words';
	return $columns;
}
/**
 * render_words_column.
 */
function render_words_column( $column ) {
	if ( 'word_count' != $column ) {
		return;
	}
	echo str_word_count( strip_tags( apply_filters( 'the_content', get_post_field( 'post_content', get_the_ID() ) ) ) );
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply