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() ) ) ) );
}

Leave a Comment