Site logo

Archived topic

hide comments time metadata

16 replies · Started by sg on November 6, 2017

Viewing posts 1–15 of 17

Hi , may i know how to hide GP comment times ?

there is code at

<div class="entry-meta comment-metadata">
						<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
							<time datetime="<?php comment_time( 'c' ); ?>">
								<?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'generatepress' ), get_comment_date(), get_comment_time() ); ?>
							</time>
						</a>
						<?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">| ', '</span>' ); ?>
						<?php
						comment_reply_link( array_merge( $args, array(
							'add_below' => 'div-comment',
							'depth'     => $depth,
							'max_depth' => $args['max_depth'],
							'before'    => '<span class="reply">| ',
							'after'     => '</span>',
						) ) );
						?>
					</div><!-- .comment-metadata -->

how do i adjust this pls. thanks

update

This should work to get rid of the comment time and move the separator bars (|) around so they look right still. It does remove the comment permalink. You would need to update and use this in a child theme to make sure it does not get overwritten in the next theme update.


					<div class="entry-meta comment-metadata">
						<?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link"> ', ' | </span>' ); ?>
						<?php
						comment_reply_link( array_merge( $args, array(
							'add_below' => 'div-comment',
							'depth'     => $depth,
							'max_depth' => $args['max_depth'],
							'before'    => '<span class="reply">',
							'after'     => '</span>',
						) ) );
						?>
					</div><!-- .comment-metadata -->

Thanks Andrew,

Do i copy the file template-tags.php to 1. childtheme/inc/template-tags.php OR 2.childtheme/template-tags.php ?

also i just need to get rid of the time, i still need to keep the dates.

Well I'm sorry, I told you wrong on both counts. Since it's in the inc folder copying to the child theme does not help! But since Tom is great about letting your override you can create your own comment function by pasting this into your child theme's functions.php. This also keeps the date and just removes the time as you originally asked!

/* Comment Template to Just Show Date */
if ( ! function_exists( 'generate_comment' ) ) :
function generate_comment( $comment, $args, $depth ) {
	$args['avatar_size'] = apply_filters( 'generate_comment_avatar_size', 50 );

	if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>

	<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
		<div class="comment-body">
			<?php _e( 'Pingback:', 'generatepress' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">', '</span>' ); ?>
		</div>

	<?php else : ?>

	<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
		<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
			<footer class="comment-meta">
				<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
				<div class="comment-author-info">
					<div class="comment-author vcard">
						<?php printf( '<cite class="fn">%s</cite>', get_comment_author_link() ); ?>
					</div><!-- .comment-author -->

					<div class="entry-meta comment-metadata">
						<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
							<time datetime="<?php comment_time( 'c' ); ?>">
								<?php printf( _x( '%1$s', '1: date', 'generatepress' ), get_comment_date() ); ?>
							</time>
						</a>
						<?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">| ', '</span>' ); ?>
						<?php
						comment_reply_link( array_merge( $args, array(
							'add_below' => 'div-comment',
							'depth'     => $depth,
							'max_depth' => $args['max_depth'],
							'before'    => '<span class="reply">| ',
							'after'     => '</span>',
						) ) );
						?>
					</div><!-- .comment-metadata -->
				</div><!-- .comment-author-info -->

				<?php if ( '0' == $comment->comment_approved ) : ?>
				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'generatepress' ); ?></p>
				<?php endif; ?>
			</footer><!-- .comment-meta -->

			<div class="comment-content">
				<?php comment_text(); ?>
			</div><!-- .comment-content -->
		</article><!-- .comment-body -->
	<?php
	endif;
}
endif;

Thanks for helping, Andrew! I adjusted your code a bit to include function_exists(), which will prevent any errors when two functions are named the same :)

excellent team work. thanks.

Sorry lil trouble here.
i added the code to my code snippets plugins, the page went blank. please advice.

Did it give you a specific error, or just a white page?

white page.

Try this code instead:

if ( ! function_exists( 'generate_comment' ) ) {
	function generate_comment( $comment, $args, $depth ) {
		$args['avatar_size'] = apply_filters( 'generate_comment_avatar_size', 50 );
		if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>

		<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
			<div class="comment-body">
				<?php _e( 'Pingback:', 'generatepress' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">', '</span>' ); ?>
			</div>

		<?php else : ?>

		<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
			<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
				<footer class="comment-meta">
					<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
					<div class="comment-author-info">
						<div class="comment-author vcard">
							<?php printf( '<cite class="fn">%s</cite>', get_comment_author_link() ); ?>
						</div><!-- .comment-author -->

						<div class="entry-meta comment-metadata">
							<?php edit_comment_link( __( 'Edit', 'generatepress' ), '<span class="edit-link">| ', '</span>' ); ?>
							<?php
							comment_reply_link( array_merge( $args, array(
								'add_below' => 'div-comment',
								'depth'     => $depth,
								'max_depth' => $args['max_depth'],
								'before'    => '<span class="reply">| ',
								'after'     => '</span>',
							) ) );
							?>
						</div><!-- .comment-metadata -->
					</div><!-- .comment-author-info -->

					<?php if ( '0' == $comment->comment_approved ) : ?>
					<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'generatepress' ); ?></p>
					<?php endif; ?>
				</footer><!-- .comment-meta -->

				<div class="comment-content">
					<?php comment_text(); ?>
				</div><!-- .comment-content -->
			</article><!-- .comment-body -->
		<?php
		endif;
	}
}

Alternatively, you can just hide it with CSS:

.comment-metadata {
    display: none;
}

the

.comment-metadata {
    display: none;
}

will hide all the date and time. i just need to hide the time.

On the other needs, pls advice how to remove the link to webpage .

code found :

<div class="comment-author vcard">
<?php printf( '<cite class="fn">%s</cite>', get_comment_author_link() ); ?>
</div><!-- .comment-author -->

Did you try the function I posted above for removing the date?

Hi tom, removing date is solved, the code is working, thanks.

i would like to remove the link to the website from user name .
pls advice. thanks.

This archived topic is closed to new replies.