Last active
August 13, 2016 01:55
-
-
Save muhfaris/1f1e735595eebbbe06f946a0e62931be to your computer and use it in GitHub Desktop.
Waktu baca, bisa untuk wordpress
This file contains hidden or 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
/* | |
Buat file dengan nama read_time.php | |
taruh di dalam main theme | |
/themes/<nama theme>/ | |
*/ | |
<?php | |
$post = get_post(); | |
$mycontent = $post->post_content; | |
$word = str_word_count(strip_tags($mycontent)); | |
$m = floor($word / 200); $s = floor($word % 200 / (200 / 60)); | |
if ($s >= 30) { | |
$m = ($m + 1); | |
} | |
$est = $m . ' minute' . ($m == 1 ? '' : 's'); ?> | |
/* | |
ini taruh di single.php | |
*/ | |
<?php include 'read-time.php'; if ($est >= 1) { echo 'Sekitar ' , $est , 'untuk membaca'; } else { echo 'kurang dari 1 menit untuk membaca'; } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment