How to display word count for posts in Genesis

Adding the following in child theme’s functions.php will display the word count in post info on single post pages in Genesis:

add_shortcode( 'word_count', 'func_word_count' );
/**
 * Register custom [word_count] shortcode to display the number of words in a post.
 *
 * @return word count.
 */
function func_word_count() {
    $content = get_post_field( 'post_content', get_the_ID() );

    $word_count = str_word_count( strip_tags( $content ) );

    return $word_count;
}

add_filter( 'genesis_post_info', 'custom_post_info_filter' );
/**
 * Customize entry meta in the entry header.
 *
 * @param string $post_info Existing Post Info.
 * @return Modified Post Info.
 */
function custom_post_info_filter( $post_info ) {
    if ( is_singular( 'post' ) ) {
        $post_info = '[post_date] by [post_author_posts_link] [post_comments] [post_edit] [[word_count] words]';
    }

    return $post_info;
}
This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.