I’ve been building a theme completely from scratch and after a straightforward process up to this point, I’ve reached the comments.php file. Again, nothing too out of the ordinary, until this:
$callback
(string) (optional) The name of a custom function to use to
open and display each comment. Using this will make your custom
function get called to display each comment, bypassing all internal
WordPress functionality in this respect. Use to customize comments
display for extreme changes to the HTML layout. Note that your
callback must include the opening<div>
,<ol>
, or<ul>
tag
(corresponding with the style parameter), but not the closing tags.
WordPress will supply the closing tag automatically, or you can use
end-callback to override this default. The callback is separate from
the end-callback to facilitate hierarchical comments. Use with
caution.
Why is this so mad? Why isn’t there a way to just have a comment.php template that gets used for each comment? (Or if there is, please do let me know)
If you prefer simple template files, you can do that with custom comment callbacks too.
Call
wp_list_comments()
with a custom callback handler:Now make that callback function very simple:
And now you can use
comment-template.php
like any other template.Here is a simple example showing you what variables are available:
You can also use the functions body of an existing callback handler like that from Twenty Twelve here, and it will work: