- This topic has 11 replies, 2 voices, and was last updated 7 years, 4 months ago by
Tom.
-
AuthorPosts
-
December 15, 2017 at 4:40 pm #450542
themedleb
How to display “Time ago” instead of regular date/time for posts and everything in the website?
December 15, 2017 at 10:54 pm #450646Tom
Lead DeveloperLead DeveloperThis might help: https://en-ca.wordpress.org/plugins/the-time-ago/
December 16, 2017 at 9:57 am #450961themedleb
It’s working, but it is good for only Latin websites, for Arabic (and maybe Hebrew too) the syntax isn’t correct, in Latin we can say “1 minute/hour/day/week/month/year” and everything above 1 will be called “minutes/hours/days/weeks/months/years”, but in Arabic it’s different, for 1 we say minute, from 2 to 10 we call them minutes, and from 11 and above we call them minute.
“The time ago” plugin doesn’t give this syntax, so the websites wouldn’t look translated properly, I already used the plugin “Meks Time Ago” and it worked so fine without any manual translation needed, I think because it uses the built-in “human time diff” of WordPress, this plugin works in archive pages and I think in everything else except the Page Headers, it stays with regular time, before the last updates of the theme it used to work even in Page Header using “Meks Time Ago” plugin, now it doesn’t.
Thanks.
December 16, 2017 at 11:16 pm #451229Tom
Lead DeveloperLead DeveloperSo it’s working everything but inside Page Headers? The Page Header module uses core functionality to build the date, so it should work the same there as anywhere else.
December 18, 2017 at 11:15 am #452370themedleb
Sorry for the late reply.
I know … because it was working, but in the last updates I think something changed in the theme or in the Page Header (in GPP) that made it stop working on just the Page Header.
December 18, 2017 at 12:04 pm #452398themedleb
I have found this filter function:
function time_ago_date( $the_date) { return human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ' .__( 'since' ); } add_filter( 'get_the_date', 'time_ago_date', 10, 1 );
It works as needed in your theme, but I need to put the word “since” in the beginning of the sentence to look properly in Arabic, however I try to move it, it shows an error before things get saved.
December 18, 2017 at 6:56 pm #452558themedleb
I get this, just wrote it like that and it worked:
return 'Since'. human_time_diff( get_the_time('U'), current_time('timestamp') );
Now can you tell me please how can I make this function filter work with updated time too?
December 18, 2017 at 8:34 pm #452600Tom
Lead DeveloperLead DeveloperInstead of
get_the_time( 'U' )
, you would useget_the_modified_time( 'U' )
for the updated time.December 18, 2017 at 8:42 pm #452602themedleb
Thanks, I made it like that:
function time_ago_date( $the_date) { return 'Since'. human_time_diff( get_the_time('U'), current_time('timestamp') ); return 'Since'. human_time_diff( get_the_modified_time('U'), current_time('timestamp') ); } add_filter( 'get_the_date', 'time_ago_date', 10, 1 );
But it didn’t work.
December 18, 2017 at 10:54 pm #452639Tom
Lead DeveloperLead DeveloperYou could do something like this:
function time_ago_date( $the_date ) { $time = human_time_diff( get_the_time('U'), current_time('timestamp') ); $updated = human_time_diff( get_the_modified_time('U'), current_time('timestamp') ); return sprintf( 'Since %1$s. Updated %2$s', $time, $updated ); } add_filter( 'get_the_date', 'time_ago_date', 10, 1 );
December 19, 2017 at 2:33 pm #453353themedleb
Thank you.
December 19, 2017 at 5:16 pm #453427Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.