Skip to content

Instantly share code, notes, and snippets.

@dnshulga
Last active June 5, 2019 13:33
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 dnshulga/01d102e76a9860368e6145bb02a44285 to your computer and use it in GitHub Desktop.
Save dnshulga/01d102e76a9860368e6145bb02a44285 to your computer and use it in GitHub Desktop.
Output of ".. hours ago". If more than 24 hours (1 day) - prints the date in common format
<?php
$time_diff = human_time_diff( get_the_date('U'), current_time('timestamp') );
if( preg_match('~day|month|year~iu', $time_diff ) )
$date = get_the_date('M d');
else
$date = $time_diff.' '.__('ago', 'project-locatization-name');
?>
<p><?php echo $date ?></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment