Nael
5/26/2018 - 2:24 PM

Post date in custom "ago" format

/**
 * Prints post time in custom date format. 
 * HOUR > - "minutes ago"
 * TODAY = - "today at"
 * TODAY < - normal date
 */
function custom_post_date(){
	// if less than an hour
	if( current_time('timestamp') - get_the_time('U') < 3600 ){
		$minutes_ago = round(( current_time('timestamp') - get_the_time('U') ) / 60);
		$date = sprintf( _nx('%s minute ago', '%s minutes ago', $minutes_ago, 'Post date in "ago" format', TEXTDOMAIN), number_format_i18n($minutes_ago) );
	}
	elseif( get_the_time('Y-m-d') == current_time('Y-m-d') ){
		$date = sprintf( _x('Today at %s', 'Post date', TEXTDOMAIN), get_the_time('G:i') );
	}
	else{
		$date = get_the_time('j M Y');
	}
	echo $date;
}