• Resolved worldless

    (@worldless)


    I don’t really wanna use the css code .comment-metadata {display: none} to hide it I just need to remove it from php…

    there is noting related to comments date in my custom theme comments.php to remove it from there and I don’t really wanna remove the following codes directly from wp-includes/class-walker-comment.php due to the future updates:

    <div class="comment-metadata">
    <a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
    <time datetime="<?php comment_time( 'c' ); ?>">
    <?php
    /* translators: 1: comment date, 2: comment time */
    printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
    ?>
    </time>
    </a>
    <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
    </div><!-- .comment-metadata -->

    I would also like to have the edit_comment_link in the given codes intact… having said that is there any way to remove it from somewhere in my function.php or anywhere else ?

    P.S. I also tried some plugins but none of them worked !!

    • This topic was modified 6 years, 7 months ago by worldless.
    • This topic was modified 6 years, 7 months ago by worldless.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello if you don’t want it through CSS the only way to change the comments in general I guess is by making your own template so that will include your own PHP calls.

    Since you mention that your theme has a comments template you can search for the get_comment_date() function if it exists somewhere in your theme. That’s what returns the date for display.

    If your theme is free maybe you can link it so we can take a look in case that might help.

    More info here as well: https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comments/

    Thread Starter worldless

    (@worldless)

    Hey Xenos

    Like I said there’s no such a code in the theme’s comments.php related to date (I could easily find and comment out the “posts date” from the theme’s template-tags.php but there’s no date code for comments in there either) I also tried looking for any dates through the theme files using Notepad C++ but I couldn’t find it anywhere else. it seems like this theme is getting the date directly from wp-includes/class-walker-comment.php…

    here is the comments.php :

    if ( post_password_required() ) {
    	return;
    }
    
    if ( have_comments() ) : ?>
    
    	<div id="comments" class="comments-area">
    
    		<?php if ( have_comments() ) : ?>
    
    			<header class="comments-header">
    
    				<h2 class="comments-title">
    					<?php comments_number( '', esc_html__( 'One Comment', 'napoli' ), esc_html__( '% comments', 'napoli' ) );?>
    				</h2>
    
    			</header><!-- .comment-header -->
    
    			<?php the_comments_navigation(); ?>
    
    			<ol class="comment-list">
    				<?php
    					wp_list_comments( array(
    						'style'      => 'ol',
    						'short_ping' => true,
    						'avatar_size' => 56,
    					) );
    				?>
    			</ol><!-- .comment-list -->
    
    			<?php the_comments_navigation(); ?>
    
    		<?php endif; // Check for have_comments(). ?>
    
    		<?php
    			// If comments are closed and there are comments, let's leave a little note, shall we?
    		if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    		?>
    		<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'napoli' ); ?></p>
    		<?php endif; ?>
    
    	</div><!-- #comments -->
    
    <?php endif;
    
    if ( comments_open() ) :
    
    	comment_form();
    
    endif;

    and here is the free theme:
    https://wordpress.org/themes/napoli/

    Because it’s missing a callback that’s why you can’t edit it.

    BUT DO NOT FEAR ! I’m here to help you solve it.

    Please add this function to your functions.php file ( prefered on your child theme )

    function xkon_custom_comment($comment, $args, $depth) {
    	if ( 'div' === $args['style'] ) {
    		$tag       = 'div';
    		$add_below = 'comment';
    	} else {
    		$tag       = 'li';
    		$add_below = 'div-comment';
    	}
    	?>
    	<<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
    	<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
    		<footer class="comment-meta">
    		<div class="comment-author vcard">
    		<?php
    		if ( 0 != $args['avatar_size'] ) {
    			echo get_avatar( $comment, $args['avatar_size'] );
    		}
    		printf( __( '<b class="fn">%s</b> <span class="says">says:</span>' ), get_comment_author_link() );
    		?>
    		</div>
    		<?php if ( '0' == $comment->comment_approved ) : ?>
    			<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
    			<br />
    		<?php endif; ?>
    		<div class="comment-metadata">
    		<?php edit_comment_link( __( 'Edit' ), '  ', '' ); ?>
    		</div>
    	</footer>
    	<div class="comment-content">
    	<?php comment_text(); ?>
    	</div>
    	<div class="reply">
    		<?php
    		comment_reply_link(
    			array_merge(
    				$args,
    				array(
    					'add_below' => $add_below,
    					'depth' => $depth,
    					'max_depth' => $args['max_depth'],
    				)
    			)
    		);
    		?>
    	</div>
    		</article>
    	<?php
    }

    And on your comments.php replace the wp_list_comments function with this :

    wp_list_comments( array(
    	'style'      => 'ol',
    	'short_ping' => true,
    	'avatar_size' => 56,
    	'callback' => 'xkon_custom_comment',
    ) );

    The result would be removing the date but leaving the Edit. Everything else is styled accordingly to the Napoli theme :).

    I’ve tested it locally and it works, but as always I’d recommend you to get a backup first of the files that you are editing.

    Thread Starter worldless

    (@worldless)

    That was amazing ! thank you so much

    No problem at all! Glad I could help 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to remove comments date through php’ is closed to new replies.