Show how many words each post has in the Posts list, to spot thin content quickly.
add_filter( 'manage_posts_columns', function ( array $columns ): array {
$columns['nahnu_words'] = 'Words';
return $columns;
} );
add_action( 'manage_posts_custom_column', function ( string $column, int $post_id ): void {
if ( 'nahnu_words' !== $column ) {
return;
}
$text = wp_strip_all_tags( strip_shortcodes( (string) get_post_field( 'post_content', $post_id ) ) );
$count = count( preg_split( '/\s+/u', trim( $text ), -1, PREG_SPLIT_NO_EMPTY ) );
echo esc_html( number_format_i18n( $count ) );
}, 10, 2 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Short posts often rank poorly and need expanding. A word count column lets you spot them in the list without opening each one.
The column strips HTML and shortcodes from each post’s content and counts words by splitting on whitespace, which works for most languages that use spaces. The number is formatted for your site’s locale.
Open Posts → All Posts. A Words column should show each post’s length.