Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Last active June 22, 2018 08:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imelgrat/ef8acd5583245d4573294f7df352a754 to your computer and use it in GitHub Desktop.
Save imelgrat/ef8acd5583245d4573294f7df352a754 to your computer and use it in GitHub Desktop.
Display posts word-count column in Wordpress post manage page: Full article at: http://imelgrat.me/wordpress/customize-wordpress-post-management-page/
function post_word_count($post_id) {
$content = get_post_field( 'post_content', $post_id );
$word_count = str_word_count( strip_tags( strip_shortcodes($content) ) );
return $word_count;
}
add_filter('manage_posts_columns', 'wordcount_column');
function wordcount_column($columns) {
$columns['wordcount'] = 'Word count';
return $columns;
}
add_action('manage_posts_custom_column', 'show_wordcount');
function show_wordcount($name)
{
global $post;
switch ($name)
{
case 'wordcount':
$wordcount = post_word_count($post->ID);
echo $wordcount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment