1

I'm trying to display something below avatar in comments. How can I filter this ? Sorry I'm a newbie with Wordpress PHP development.

In comment.php of my child theme I have :

wp_list_comments(
    array(
        'style'       => 'ol',
        'short_ping'  => true,
        'avatar_size' => 60,
    )

);

I think, I have to do something here or in functions.php

1

I am giving you example from storefront WordPress theme because it's the best theme which explains everything what you want to know so here the code which is in it's comments.php

<ol class="comment-list">
<?php
wp_list_comments( array(
    'style'      => 'ol',
    'short_ping' => true,
    'callback'   => 'storefront_comment',
) );
?>

here storefront_comment is a callback function which is defined in storefront-template-functions.php located at inc folder. Here the function code

if ( ! function_exists( 'storefront_comment' ) ) {
/**
 * Storefront comment template
 *
 * @param array $comment the comment array.
 * @param array $args the comment args.
 * @param int   $depth the comment depth.
 * @since 1.0.0
 */
function storefront_comment( $comment, $args, $depth ) {
    if ( 'div' == $args['style'] ) {
        $tag = 'div';
        $add_below = 'comment';
    } else {
        $tag = 'li';
        $add_below = 'div-comment';
    }
    ?>
    <<?php echo esc_attr( $tag ); ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
    <div class="comment-body">
    <div class="comment-meta commentmetadata">
        <div class="comment-author vcard">
        <?php echo get_avatar( $comment, 128 ); ?>
        <?php printf( wp_kses_post( '<cite class="fn">%s</cite>', 'storefront' ), get_comment_author_link() ); ?>
        </div>
        <?php if ( '0' == $comment->comment_approved ) : ?>
            <em class="comment-awaiting-moderation"><?php esc_attr_e( 'Your comment is awaiting moderation.', 'storefront' ); ?></em>
            <br />
        <?php endif; ?>
        <a href="<?php echo esc_url( htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ); ?>" class="comment-date">
            <?php echo '<time datetime="' . get_comment_date( 'c' ) . '">' . get_comment_date() . '</time>'; ?>
        </a>
    </div>
    <?php if ( 'div' != $args['style'] ) : ?>
    <div id="div-comment-<?php comment_ID() ?>" class="comment-content">
    <?php endif; ?>
    <div class="comment-text">
    <?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'] ) ) ); ?>
    <?php edit_comment_link( __( 'Edit', 'storefront' ), '  ', '' ); ?>
    </div>
    </div>
    <?php if ( 'div' != $args['style'] ) : ?>
    </div>
    <?php endif; ?>
<?php
}

}

and under <div class="comment-author vcard"> line you can see avatar image is getting and underneath it custom data is shown. You can customize it as you like.

| improve this answer | |
  • Please try to answer the question. How is OP supposed to use this website? Why this website and not the official handbooks? How could OP "display something below avatar"? – kero Sep 24 '18 at 18:13
  • since i am new to this platform but i try to find problem solution as quick as possible, so it was just an plain answer but now it's re-edited with brief. Thank you for pointing it out and making correction to it. – Vinit Sep 24 '18 at 18:51
  • First of all I didn't mean to be rude - if I was I am sorry. Now to your edit: Isn't storefront a theme? I think Jack Johansson's comment on the question already goes in the right direction – kero Sep 25 '18 at 7:52
  • I already mention that storefront WordPress theme and yes Jack's comment taking him to right direction but as a newbie i feel afraid when i don't see what i want in front side, if you are familiar with WordPress then you can understand what his link is saying, from my code and explanation he can check ohh! so storefront theme already doing it. let me see and then he can learn where and how things are working in order to show it upfront. forgive me if my language is hard or anything. – Vinit Sep 25 '18 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.