A simple comment walker that extends existing WordPress functionality by replacing the html5_comment
function in Walker_Comment
.
This walker should work with all WordPress themes, but we recommend to use Sage by Roots if you're building from scratch.
For Sage:
- Add CommentWalker.php to the
/src
folder - In functions.php, add CommentWalker to the required files array (line 51)
Other themes:
- Add CommentWalker.php to whatever directory theme functions are placed
- In functions.php use
require_once
to add the walker in to runtime
After adding in, using the comment walker is pretty easy. Wherever a wp_list_comments
is located, add 'walker' => new Comment_Walker
and set 'format' => 'html5'
to utilize it. It should look like the following:
wp_list_comments([
'avatar_size' => 50,
'format' => 'html5',
'short_ping' => true,
'style' => 'li',
'walker' => new Comment_Walker
]);
Feel free to contribute to this project. The template could certainly be refactored, and I will come back to it as I work on future projects. I will credit every contributor below.