Skip to content

Instantly share code, notes, and snippets.

@muhfaris
Last active August 13, 2016 01:55
Show Gist options
  • Save muhfaris/1f1e735595eebbbe06f946a0e62931be to your computer and use it in GitHub Desktop.
Save muhfaris/1f1e735595eebbbe06f946a0e62931be to your computer and use it in GitHub Desktop.
Waktu baca, bisa untuk wordpress
/*
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