Change date format/display for comments


#1

Hi,

I’m running rtPanel 4.1.5. Currently date in comments show up like this, for example: March 27, 2015 at 4:30 pm

How can I change it to, for example: March 27, 2015 ?

Thanks.


#2

Hello sadanduseless,

Are you doing changes in rtPanel child theme or rtPanel theme itself?


#3

I’m doing changes on a child theme.


#4

Hi sadanduseless,

Follow these steps to change date format:

  1. First, Override parent theme comments.php in your child theme. Just copy comments.php in child theme.
  2. Then, replace line 39 in comments.php in child theme with below line. $args = ( $rtp_post_comments[‘comment_separate’] ) ? ‘callback=rtp_new_comment_list&type=comment’ : ‘callback=rtp_new_comment_list&type=all’;
  3. Define new function ‘rtp_new_comment_list’ in child hteme’s functions.php. In below function I’ve removed the time from comment date.
function rtp_new_comment_list( $comment, $args, $depth ) {
            $GLOBALS['comment'] = $comment;
            global $rtp_post_comments;
        ?>
                <li <?php comment_class( 'clearfix' ); ?> id="li-comment-<?php comment_ID(); ?>">
        
                    <div id="comment-<?php comment_ID(); ?>" class="comment-body clearfix"><?php
                        if ( $rtp_post_comments['gravatar_show'] ) { // check if gravatar support is enabled
                            if ( isset( $rtp_post_comments['gravatar_size'] ) ) {
                                $gravatar_size = apply_filters( 'rtp_gravatar_size', $rtp_post_comments['gravatar_size'] );
                            } else {
                                $gravatar_size = apply_filters( 'rtp_gravatar_size', 48 );
                            } ?>
                            <div class="vcard">
                                <?php echo get_avatar( $comment, $gravatar_size ); 
                                rtp_hook_after_comment_author_avatar()?>
                            </div><?php
                        } ?>
        
                        <div class="comment-author clearfix <?php echo ( $rtp_post_comments['gravatar_show'] ) ? '' : 'no-gravatar';

?>"> <?php comment_author_link(); ?> <?php printf( __( ‘%1$s’, ‘rtPanel’ ), get_comment_date()); ?> <?php edit_comment_link( __( '[ edit ]', 'rtPanel' ) ); ?> <?php echo ( $comment->comment_approved == ‘0’ ) ? ‘’ . __( 'Your comment is awaiting moderation. ', ‘rtPanel’ ) . ‘’ : ‘’; ?>

                        <div class="comment-text">
                            <?php comment_text(); ?>
                        </div>
                        <div class="rtp-reply rtp-common-link"><?php comment_reply_link( array_merge( $args, array(

‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’], ‘reply_text’ => __( ‘Reply’, ‘rtPanel’ ), ) ) ); ?>

                    </div><!-- .comment-body --><?php
        }

#5

Thank you, umeshnevase, it worked!


#6

You’re welcome sadanduseless


#7