WordPress post to display minutes ago with simple code
To Display Post timing with minutes ago, hours ago in wordpress theme you have to follow the below instructions
Step 1
Copy & paste the below code to your theme function.php
function vip_relative_time() { $post_date = get_the_time('U'); $delta = time() - $post_date; if ( $delta < 60 ) { echo 'Less than a minute ago'; } elseif ($delta > 60 && $delta < 120){ echo 'About a minute ago'; } elseif ($delta > 120 && $delta < (60*60)){ echo strval(round(($delta/60),0)), ' minutes ago'; } elseif ($delta > (60*60) && $delta < (120*60)){ echo 'About an hour ago'; } elseif ($delta > (120*60) && $delta < (24*60*60)){ echo strval(round(($delta/3600),0)), ' hours ago'; } else { echo the_time('j\<\s\u\p\>S\<\/\s\u\p\> M y g:i a'); } }
Step 2
Copy & paste the below code with in your theme post loop file where ever you want to display time
<?php vip_relative_time(); ?>