Created
July 10, 2015 12:43
-
-
Save purzlbaum/d768ef6e1a6c3383d023 to your computer and use it in GitHub Desktop.
Reading Time for WordPress 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 | |
$mycontent = $post->post_content; // wordpress users only | |
$word = str_word_count( strip_tags( $mycontent ) ); | |
$m = floor( $word / 200 ); | |
$s = floor( $word % 200 / ( 200 / 60 ) ); | |
$estS = $s . ' Sekunde' . ( $s == 1 ? '' : 'n' ); | |
$estMs = $m . ' Minute' . ( $m == 1 ? '' : 'n' ) . ', ' . $s . ' Sekunde' . ( $s == 1 ? '' : 'n' ); | |
?> | |
<article> | |
<?php | |
if ( $m == 0 ) { | |
echo $estS; | |
} else { | |
echo $estMs; | |
} | |
?> Lesezeit | |
</article> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment