• Resolved Andry

    (@blackstar1991)


    Can someone tell me how to wrap the output of comments in a tag. It’s in standard comments block wp-includes/class-walker-comment.php

    <div class="comment-meta commentmetadata">
    			<?php
    			printf(
    				'<a href="%s">%s</a>',
    				esc_url( get_comment_link( $comment, $args ) ),
    				sprintf(
    					/* translators: 1: Comment date, 2: Comment time. */
    					__( '%1$s at %2$s' ),
    					get_comment_date( '', $comment ),
    					get_comment_time()
    				)
    			);
    
    			edit_comment_link( __( '(Edit)' ), ' &nbsp;&nbsp;', '' );
    			?>
    		</div>

    How make wrapper <div> for comment content? It’s posible to add it wrapper block for core WordPress <div class=”comment-content”></div>?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The “comment-content” element is produced from Walker_Comment::html5_comment(). (starting at line 469). The problem is this method is protected and you cannot override it in an extended class. However, you can override Walker_Comment::start_el(), which calls html5_comment().

    Instead of replicating the bulk of this method, call the parent method, then alter the established $output value which was passed by reference so you can directly manipulate the output string, adding your desired HTML tags.

    While extending a walker class is an elegant solution, it gets kind of messy if you don’t clearly understand what’s going on. An alternative would be to have wp_list_comments() return the comment HTML instead of outputting it. Create a wrapper function which calls it, then use PHP search and replace functions to modify the entire HTML as needed, then echo out the entire thing.

    Thread Starter Andry

    (@blackstar1991)

    Thanks for answer. It’s a pity that developers have to suffer with the development of simple things.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘class-walker-comment.php wrap comment to block’ is closed to new replies.