January 05, 2022
Works with Gutenberg.
// Add WordPress WordCount Column
add_filter('manage_posts_columns', 'crunchify_add_wordcount_column');
function crunchify_add_wordcount_column($crunchify_columns) {
$crunchify_columns['crunchify_wordcount'] = 'Word Count';
return $crunchify_columns;
}
// Show WordCount in Admin Panel
add_action('manage_posts_custom_column', 'crunchify_show_wordcount');
function crunchify_show_wordcount($name)
{
global $post;
switch ($name)
{
case 'crunchify_wordcount':
$crunchify_wordcount = crunchify_post_wordcount($post->ID);
echo $crunchify_wordcount;
}
}
// Get individual post word count
function crunchify_post_wordcount($post_id) {
$crunchify_post_content = get_post_field( 'post_content', $post_id );
$crunchify_final_wordcount = str_word_count( strip_tags( strip_shortcodes($crunchify_post_content) ) );
return $crunchify_final_wordcount;
}