[Resolved] Display "Time ago"

Home Forums Support [Resolved] Display "Time ago"

Home Forums Support Display "Time ago"

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #450542
    themedleb

    How to display “Time ago” instead of regular date/time for posts and everything in the website?

    #450646
    Tom
    Lead Developer
    Lead Developer
    #450961
    themedleb

    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.

    #451229
    Tom
    Lead Developer
    Lead Developer

    So 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.

    #452370
    themedleb

    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.

    #452398
    themedleb

    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.

    #452558
    themedleb

    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?

    #452600
    Tom
    Lead Developer
    Lead Developer

    Instead of get_the_time( 'U' ), you would use get_the_modified_time( 'U' ) for the updated time.

    #452602
    themedleb

    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.

    #452639
    Tom
    Lead Developer
    Lead Developer

    You 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 );
    #453353
    themedleb

    Thank you.

    #453427
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.