Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Word count column in the posts list

Shows how many words each post has in the posts list.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Admin area
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.