Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Date/Time format in posts and comments

  • 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.

  • 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 );
  • 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 ) );
    
  • Glad to hear that!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.