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.
Thanks for answer. It’s a pity that developers have to suffer with the development of simple things.
(@blackstar1991)
3 years, 5 months ago
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
How make wrapper <div> for comment content? It’s posible to add it wrapper block for core WordPress <div class=”comment-content”></div>?