Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Created June 1, 2012 23:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jazzsequence/2855707 to your computer and use it in GitHub Desktop.
Save jazzsequence/2855707 to your computer and use it in GitHub Desktop.
a better WordPress human_time_diff
<?php
$last_modified = human_time_diff( the_modified_date('U','','', false), current_time('timestamp') );
$number_of_x = preg_replace('/[^0-9]*/', '', $last_modified);
if ( strpos( $last_modified, 'min' ) || strpos( $last_modified, 'hour' ) || strpos($last_modified, 'sec' ) ) {
$wiki_date = $last_modified;
} elseif ( $number_of_x > 365 ) {
$wiki_date = __( 'a long time' );
} elseif ( $number_of_x >= 180 ) {
$wiki_date = __( 'less than a year' );
} elseif ( $number_of_x >= 60 ) {
$wiki_date = __( 'a couple months' );
} elseif ( $number_of_x >= 30 ) {
$wiki_date = __( 'a month' );
} elseif ( $number_of_x >= 14 ) {
$wiki_date = __( 'a couple weeks' );
} elseif ( $number_of_x >= 7 ) {
$wiki_date = __( 'a week' );
} elseif ( ( $number_of_x <= 3 ) && ( $number_of_x > 1 ) ) {
$wiki_date = __( 'a couple days' );
} else {
$wiki_date = human_time_diff( the_modified_date('U','','', false), current_time('timestamp') );
} ?>
<?php echo sprintf( __( 'Last updated %s ago' ), $wiki_date ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment