Last active
August 30, 2018 13:18
-
-
Save tallesairan/f6e107663868561b36620dd61a096b2a to your computer and use it in GitHub Desktop.
Display post time ago, eg: 37 minutes ago.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function postedAgo() { | |
| $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', 'talles' ), 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; | |
| } | |
| echo postedAgo(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment