-
kenmac
Hi,
I took over this site three years ago and one thing that has always bothered me is that posts contain the date of posting but not the time whereas the comments contain both the date and time.
I changed the date format on Settings->General to contain the time (format: F j, Y g:i a) but the result is that the time on the posts is showing. However, the date and time on the comments shows the time twice. I then decided to set the time format to blanks but then the comments contain a trailing “at”, which doesn’t look nice.
I think that the solution I want is for the time format to be ignored in comments but I can’t figure out how to do it.
I hope the above makes sense and I hope that you are able to help.
-
Alvind
Hi there,
Try adding this snippet:
function remove_comment_date_at_separator( $translated, $text, $context, $domain ) { // Only target this specific string in the generatepress domain if ( $domain === 'generatepress' && $text === '%1$s at %2$s' && $context === '1: date, 2: time' ) { return '%1$s'; } return $translated; } add_filter( 'gettext_with_context', 'remove_comment_date_at_separator', 10, 4 ); function custom_comment_date_format( $date, $format = '', $comment = null ) { return date_i18n( 'F j, Y', strtotime( $comment->comment_date ) ); } add_filter( 'get_comment_date', 'custom_comment_date_format', 10, 3 );
-
kenmac
Thanks Alvind, that worked a treat. I changed the pertinent line as follows:
return date_i18n( 'F j, Y \a\t g:i a', strtotime( $comment->comment_date ) );
-
Alvind
Glad to hear that!
- You must be logged in to reply to this topic.