Project Management, WordPress

Time ago implementation in WordPress

Time ago can be implemented in the WordPress Posts using get_the_time() and human_time_diff() functions.

$postedTime = get_the_time(‘U’,$post->ID);
get_the_time() function retrieves the time at which the post was written.

human_time_diff( int $from, int $to ), determines the difference between two timestamps by providing the posted date of the post and current time.

$timeAgo = human_time_diff($postedTime ,current_time( ‘U’ ));

Example in a WP loop :

Click to learn more about get_the_time() and human_time_diff() functions in codex.

Hits: 14

Standard