Skip to content

Instantly share code, notes, and snippets.

@mindctrl
Forked from BinaryMoon/wp_human_time_diff.php
Created May 7, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindctrl/84cd0aa93dcb89fe6d789efd1f8122e0 to your computer and use it in GitHub Desktop.
Save mindctrl/84cd0aa93dcb89fe6d789efd1f8122e0 to your computer and use it in GitHub Desktop.
Human Time Difference Function for WordPress
<?php
/**
* Display the post time in a human readable format
*
* @return string
*/
function carmack_human_time_diff() {
$post_time = get_the_time( 'U' );
$time_now = date( 'U' );
// Use human time if less that 60 days ago, otherwise display the date
// Uses the WordPress internal function human_time_diff
// 60 seconds * 60 minutes * 24 hours * 90 days.
if ( $post_time > $time_now - ( 60 * 60 * 24 * 90 ) ) {
$human_time = sprintf( esc_html__( '%s ago', 'carmack' ), human_time_diff( $post_time, current_time( 'timestamp' ) ) );
} else {
$human_time = get_the_date();
}
$human_time = sprintf( '<span class="post-human-time">%s</span>', $human_time );
return $human_time;
}
@Abid-Noyon
Copy link

Abid-Noyon commented Jul 14, 2020

How to use this code? On my site TechNewsAL.Com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment