WordPress.org

Forums

Showing 'd' instead of 'days' (3 posts)

  1. applegateian
    Member
    Posted 1 year ago #

    Hi

    I'm using the following to show '3 days ago' for example for each post. Is there a way to change the word 'days' to just say 'd'?

    <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' '; ?>

    Thanks

  2. stylishjm
    Member
    Posted 1 year ago #

    This would require editing core wordpress files as far as I know.

    Go to wp-includes/formatting.php

    Around line 2101 (just search for function human_time_diff) you will see

    $since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
     } elseif ( ( $diff <= DAY_IN_SECONDS ) && ( $diff > HOUR_IN_SECONDS ) ) {
    $hours = round( $diff / HOUR_IN_SECONDS );
    if ( $hours <= 1 ) {
    $hours = 1;
    }
    $since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
     } elseif ( $diff >= DAY_IN_SECONDS ) {
    $days = round( $diff / DAY_IN_SECONDS );
    if ( $days <= 1 ) {
    $days = 1;
    }
    $since = sprintf( _n( '%s day', '%s days', $days ), $days );

    so change %s days to %s d or whatever you want!

    Just remember to backup that file incase of mistakes, and any WordPress Core updates will overwrite any changes you make!

  3. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    Never, ever edit core files. Neither encourage others to do so. It can create more problems than solving, including bringing down your whole site and opening your site an easy target to hackers.

Topic Closed

This topic has been closed to new replies.

About this Topic