I need to show the email adress in the comments

So I'm working on a site where people post their testimonials in the comment section of a certain page. The people know that their email will get shown and have given us permission to show it to the public so they can be asked questions about their testimonial via email.

Problem is: how do I make it happen so that the email adress gets shown? What piece of code do I have to post where? Please advise. Thank you very much.

  • Vinod Dalvi

    Hi @Sebastian,

    I hope you are well today and thank you for your question.

    Actually it depends on the parent theme comments code, adding the following code in the functions.php file of my default WordPress Twenty Twelve child theme worked for me.

    if ( ! function_exists( 'twentytwelve_comment' ) ) :
    /**
     * Template for comments and pingbacks.
     *
     * To override this walker in a child theme without modifying the comments template
     * simply create your own twentytwelve_comment(), and that function will be used instead.
     *
     * Used as a callback by wp_list_comments() for displaying the comments.
     *
     * @since Twenty Twelve 1.0
     */
    function twentytwelve_comment( $comment, $args, $depth ) {
    	$GLOBALS['comment'] = $comment;
    	switch ( $comment->comment_type ) :
    		case 'pingback' :
    		case 'trackback' :
    		// Display trackbacks differently than normal comments.
    	?>
    	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
    		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
    	<?php
    			break;
    		default :
    		// Proceed with normal comments.
    		global $post;
    	?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    		<article id="comment-<?php comment_ID(); ?>" class="comment">
    			<header class="comment-meta comment-author vcard">
    				<?php
    					echo get_avatar( $comment, 44 );
    					printf( '<cite><b class="fn">%1$s</b> ( <a href="mailto:%2$s">%3$s</a> ) %4$s</cite>',
    						get_comment_author_link(), get_comment_author_email(), get_comment_author_email(),
    						// If current post author is also comment author, make it known visually.
    						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
    					);
    					printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
    						esc_url( get_comment_link( $comment->comment_ID ) ),
    						get_comment_time( 'c' ),
    						/* translators: 1: date, 2: time */
    						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
    					);
    				?>
    			</header><!-- .comment-meta -->
    
    			<?php if ( '0' == $comment->comment_approved ) : ?>
    				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
    			<?php endif; ?>
    
    			<section class="comment-content comment">
    				<?php comment_text(); ?>
    				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
    			</section><!-- .comment-content -->
    
    			<div class="reply">
    				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    			</div><!-- .reply -->
    		</article><!-- #comment-## -->
    	<?php
    		break;
    	endswitch; // end comment_type check
    }
    endif;

    The function get_comment_author_email is used in the above code to retrieve the comment author's email address.

    Best Regards,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.