Skip to:
Content
Pages
Categories
Search
Top
Bottom

how to change the freshness timing type?


  • likipadhy
    Participant

    @likipadhy

    actually freshness shows something like this 1 hour 50 minutes ago
    i want to show something like this 1hr50min ago.how to do it?
    if i posted in wrong section please move this to right section

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,
    The section is fine 🙂

    You will have to change the regular expression inside, but the basic function would look like this:

    function bbptoolkitpc_shorten_freshness_time($return) {
    	$bbptoolkit_short_fresh = get_option('bbptoolkit-short-fresh', false);
    	if ($bbptoolkit_short_fresh) {
    		$return = preg_replace( '/, .*[^ago]/', ' ', $return );
    	}
    	return $return;
    }
    add_filter( 'bbp_get_time_since', 'bbptoolkitpc_shorten_freshness_time' );
    add_filter( 'bp_core_time_since', 'bbptoolkitpc_shorten_freshness_time');

    Pascal.


    likipadhy
    Participant

    @likipadhy

    @casiepa should i insert this in themes function file?ll it shorten day timings as well? like 1d50h

    You will first have to rework it.
    As it is, it will only remove the last part, so ‘1 hour, 50 minutes ago’ will become ‘1 hour ago’ and ‘2 months, 5 days ago’ would become ‘2 months ago’ (so it just strips off the part after the comma, also only works in english as it looks for the word ‘ago’).

    The best place is always a function file in a CHILD theme to avoid that you loose this when your theme updates. Or create a small plugin that would hold this.

    Pascal.

    Well, for your specific case, you would probably go with:

    function bbptoolkitpc_shorten_freshness_time($return) {
    	$return = str_replace( "hour", "hr", $return );
    	$return = str_replace( "minutes", "min", $return );
    	return $return;
    }
    add_filter( 'bbp_get_time_since', 'bbptoolkitpc_shorten_freshness_time' );
    add_filter( 'bp_core_time_since', 'bbptoolkitpc_shorten_freshness_time');

    Pascal.


    likipadhy
    Participant

    @likipadhy

    @casiepa it worked.thank you.please accept it.

    We don’t accept responses here, we just accept thanks 🙂

    You’re welcome,
    Pascal.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar