Word Count Column for Posts
Adds a Words column to the Posts list showing the approximate length of each post.
Opens WPIDE on
Code
add_filter( 'manage_post_posts_columns', function ( $columns ) {
$columns['wpide_words'] = 'Words';
return $columns;
} );
add_action( 'manage_post_posts_custom_column', function ( $column, $post_id ) {
if ( 'wpide_words' !== $column ) {
return;
}
$text = wp_strip_all_tags( strip_shortcodes( (string) get_post_field( 'post_content', $post_id ) ) );
echo esc_html( number_format_i18n( str_word_count( $text ) ) );
}, 10, 2 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.