WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the function echo time_ago() that displays the time like this:

5 days ago what's the best way to change it to 5d ago ?

My research led me to human_time_diff() function located in "formatting.php" So I have tried directly editing the function located at /wp-includes/formatting.php but when I change "hours" to "h" and so on... it goes crazy and gives me errors. I know modifying the core isn't the best way, so any ideas? Thank you.

share|improve this question
up vote 4 down vote accepted

There is no filter for output of that function. You can fork (copy/rename/edit) it or add wrapper that will replace strings in output like this:

function short_time_diff( $from, $to = '' ) {

    $diff = human_time_diff($from,$to);

    $replace = array(
        'hour'  => 'h',
        'hours' => 'h',
        'day'   => 'd',
        'days'  => 'd',

    return strtr($diff,$replace);

PS afterthought - actually strings are localized so there is translation filter to use... But stuff to replace is to generic and that will risk breaking it elsewhere.


Since WP 4.0 there is a filter available for human_time_diff:

add_filter( 'human_time_diff', function($since, $diff, $from, $to) {

    $replace = array(
        'hour'  => 'h',
        'hours' => 'h',
        'day'   => 'd',
        'days'  => 'd',

    return strtr($since, $replace);

}, 10, 4 );
share|improve this answer
This strikes me as an exceedingly messy solution. Particularly, since it won't continue to work if the site has been translated. I would strongly reccomend creating a copy of <code>human_time_diff()</code> and then modifying the string literals, rather than a mickey moused string replacement solution. – WhIteSidE Apr 30 '11 at 10:01
@WhIteSidE I had covered fork as first option in my answer. – Rarst Apr 30 '11 at 10:10
@whiteside - not sure there's any need to refer to a working solution as "mickey moused", particularly since the term is "mickey mouse'. Why not submit your solution as an answer and let the votes decide?! – anu Apr 30 '11 at 11:22
Thank you. I have accepted the solution. I just simply copy/renamed/edited the function in my themes functions.php and it works great!@WhIteSidE Thanks for the input, perhaps you could have provided the answer you felt works better. – Pwn Apr 30 '11 at 11:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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