Created
February 15, 2019 10:56
-
-
Save imelgrat/a3b162f12c5748578178672b3a996fd6 to your computer and use it in GitHub Desktop.
Custom function that takes a WordPress post ID and returns the number of words in the post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Count Post Words. | |
* | |
* Custom function that takes a WordPress post ID and returns the number of words in the post. | |
* You should paste it on your theme's functions.php file. | |
* | |
* @link https://imelgrat.me/wordpress/customize-wordpress-post-management-page/ | |
* | |
* @param int $post_id The Post ID | |
* | |
* @return int The word count. | |
*/ | |
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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment