0

I'd like to format the time-ago date format from 5 min to 5m. I can edit the formatting.php file and make the edit but should I? Should I instead declare the edit in the functions.php file?

From the formatting.php file:

function human_time_diff( $from, $to = '' ) {
    if ( empty( $to ) ) {
        $to = time();
    }

    $diff = (int) abs( $to - $from );

    if ( $diff < HOUR_IN_SECONDS ) {
        $mins = round( $diff / MINUTE_IN_SECONDS );
        if ( $mins <= 1 )
            $mins = 1;
        /* translators: Time difference between two dates, in minutes (min=minute). 1: Number of minutes */
        $since = sprintf( _n( '%s min', '%s min', $mins ), $mins );
    }

As you can see in the last time, I can change '%s min' to '%sm' which does the trick. If WordPress discourages editing the formatting.php file, how would I make this edit in functions.php?

1 Answer 1

1

The human_time_diff function applies a filter to the results at the end of the function call.

return apply_filters( 'human_time_diff', $since, $diff, $from, $to );

So, use that filter to replace the text with what you want it to be instead.

https://codex.wordpress.org/Plugin_API#Filters

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.