Word count column in the posts list
Shows how many words each post has in the posts list.
<?php
add_filter(
'manage_posts_columns',
static function ( $columns, $post_type = 'post' ) {
if ( 'post' === $post_type ) {
$columns['snipfire_words'] = __( 'Words' );
}
return $columns;
},
10,
2
);
add_action(
'manage_posts_custom_column',
static function ( $column, $post_id ) {
if ( 'snipfire_words' === $column ) {
$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
);
Good to know
Counts Latin-script words; Greek and other alphabets are counted by spaces only roughly.
In these packs
- More admin tweaks: Useful columns, a tidier admin bar, a welcome box for clients, and fewer menus for editors.