• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to Change Comment Date to "Over a year ago" ?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › How to Change Comment Date to "Over a year ago" ?

This topic is: not resolved
  • This topic has 4 replies, 2 voices, and was last updated 8 years, 8 months ago by Regev.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 27, 2017 at 5:40 am #202070
    Regev
    Participant

    I noticed that some posts that I have (of 300-400 comments each), tend to get commented less and less over time. This might be because there are no more questions to ask, but I have a feeling that it's because some of the comments are from 2012, which adds the feeling that the thread is 'dead' (which is definitely not). So I was thinking of changing any comment that is over a year old to "Over a year ago." instead of the date and year. How can I do that?

    Thanks.

    February 27, 2017 at 6:14 am #202071
    Victor Font
    Moderator

    The comments structure in the Genesis Framework uses standard WordPress functionality to display the comments. Unfortunately, there aren't any filters in the code to make it easy to change the way dates are displayed. To change what you want requires writing a custom callback function to override what the framework provides. The first part requires changing the callback in the defaults passed to wp_list_comments(). The second part requires changing the get_comment_date() and get_comment_time() to human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) in the new custom callback. I've tested the code below with the Genesis Sample theme. You may want to tweak the display to your liking, but the hard work is done.

    Add this code to your child theme's functions.php. It assumes you are using a HTML5 theme. This will not work on the older XHTML themes.

    add_filter( 'genesis_comment_list_args', 'my_custom_comment_callback' );
    function my_custom_comment_callback( $defaults ) {
    
        $defaults['callback'] = genesis_html5() ? 'my_html5_comment_callback' : 'genesis_comment_callback';
        return $defaults;
    }
    
    function my_html5_comment_callback( $comment, array $args, $depth ) {
        $GLOBALS['comment'] = $comment; ?>
    
    	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
    	<article <?php echo genesis_attr( 'comment' ); ?>>
    
    		<?php do_action( 'genesis_before_comment' ); ?>
    
    		<header <?php echo genesis_attr( 'comment-header' ); ?>>
    			<p <?php echo genesis_attr( 'comment-author' ); ?>>
    				<?php
    				echo get_avatar( $comment, $args['avatar_size'] );
    
    				$author = get_comment_author();
    				$url    = get_comment_author_url();
    
    				if ( ! empty( $url ) && 'http://' !== $url ) {
    					$author = sprintf( '<a href="%s" %s>%s</a>', esc_url( $url ), genesis_attr( 'comment-author-link' ), $author );
    				}
    
    				/**
    				 * Filter the "comment author says" text.
    				 *
    				 * Allows developer to filter the "comment author says" text so it can say something different, or nothing at all.
    				 *
    				 * @since unknown
    				 *
    				 * @param string $text Comment author says text.
    				 */
    				$comment_author_says_text = apply_filters( 'comment_author_says_text', __( 'says', 'genesis' ) );
    
    				if ( ! empty( $comment_author_says_text ) ) {
    					$comment_author_says_text = '<span class="says">' . $comment_author_says_text . '</span>';
    				}
    
    				printf( '<span itemprop="name">%s</span> %s', $author, $comment_author_says_text );
    				?>
    			</p>
    
    			<?php
    			/**
    			 * Allows developer to control whether to print the comment date.
    			 *
    			 * @since 2.2.0
    			 *
    			 * @param bool   $comment_date Whether to print the comment date.
    			 * @param string $post_type    The current post type.
    			 */
    			$comment_date = apply_filters( 'genesis_show_comment_date', true, get_post_type() );
    
    			if ( $comment_date ) {
    				printf( '<p %s>', genesis_attr( 'comment-meta' ) );
    				printf( '<time %s>', genesis_attr( 'comment-time' ) );
    				printf( '<a href="%s" %s>', esc_url( get_comment_link( $comment->comment_ID ) ), genesis_attr( 'comment-time-link' ) );
    				echo    esc_html( human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) );
    				echo    '</a></time></p>';
    			}
    
    			edit_comment_link( __( '(Edit)', 'genesis' ), ' ' );
    			?>
    		</header>
    
    		<div <?php echo genesis_attr( 'comment-content' ); ?>>
    			<?php if ( ! $comment->comment_approved ) : ?>
    				<?php
    				/**
    				 * Filter the "comment awaiting moderation" text.
    				 *
    				 * Allows developer to filter the "comment awaiting moderation" text so it can say something different, or nothing at all.
    				 *
    				 * @since unknown
    				 *
    				 * @param string $text Comment awaiting moderation text.
    				 */
    				$comment_awaiting_moderation_text = apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'genesis' ) );
    				?>
    				<p class="alert"><?php echo $comment_awaiting_moderation_text; ?></p>
    			<?php endif; ?>
    
    			<?php comment_text(); ?>
    		</div>
    
    		<?php
    		comment_reply_link( array_merge( $args, array(
    			'depth'  => $depth,
    			'before' => sprintf( '<div %s>', genesis_attr( 'comment-reply' ) ),
    			'after'  => '</div>',
    		) ) );
    		?>
    
    		<?php do_action( 'genesis_after_comment' ); ?>
    
    	</article>
    	<?php
    	// No ending </li> tag because of comment threading.
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 27, 2017 at 6:29 am #202072
    Regev
    Participant

    Holy @!# thanks Victor! But does this code shoe the time difference? (19 months ago, 7 months ago, etc)? I just want it to show "Over a year ago." So 5 years ago or 15 months ago would look the same. Thanks again, you rock.

    February 27, 2017 at 6:44 am #202073
    Victor Font
    Moderator

    It uses the WordPress human_time_diff() function. https://codex.wordpress.org/Function_Reference/human_time_diff

    If you want anything beyond what that function displays, you'll have to write it yourself. The framework also has a function called genesis_human_time_diff() to display relative depth. You can copy this and change it for your own purposes and use your version in place of the WordPress function.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 27, 2017 at 6:52 am #202074
    Regev
    Participant

    Oh, then it's not what I was looking for. The whole idea is to eliminate that sense of "obsoleteness" that old dates give ("3.5 years ago" etc doesn't solve that). If I could change any 1y/o+ comment to "Over a year ago.", or maybe even better - "Over 10 months ago.", that would make the posts much livelier in perception. Anybody has any idea how to do that?

    Victor thanks again for the generous willingness to help out.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble