Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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.

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
1  
@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

 
discard

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.