php - How can i implement an estimated reading time feature in wordpress? -
i trying integrate estimated reading time in wordpress theme , can't seem work. took code here http://wptavern.com/estimated-time-to-read-this-post-eternity . pasted functions.php
function bm_estimated_reading_time() { $post = get_post(); $words = str_word_count( strip_tags( $post->post_content ) ); $minutes = floor( $words / 120 ); $seconds = floor( $words % 120 / ( 120 / 60 ) ); if ( 1 < = $minutes ) { $estimated_time = $minutes . ' minute' . ($minutes == 1 ? '' : 's') . ', ' . $seconds . ' second' . ($seconds == 1 ? '' : 's'); } else { $estimated_time = $seconds . ' second' . ($seconds == 1 ? '' : 's'); } return $estimated_time; } and called
<p class="ert"><?php bm_estimated_reading_time() ?></p> in content-single.php, right after author link , nothing gets displayed. if inspect post in chrome can see paragraph, empty. doing wrong, or else should doing instead ?
the function returns value. you're not echoing returned value.
<?php echo bm_estimated_reading_time() ?>
Comments
Post a Comment