Getting full code of wp_list_comments instead of replacing it

I am wondering if this is possible, because I don’t want to edit the standard/default lay-out of the comments. I already tried that, but somehow it won’t put the list items in my div sections. That’s why I am trying to find the full code of wp_list_comments; I want to make changes to the list items in there…

Is this possible? If yes, where can I find it?

Answer

Check the Codex for wp_list_comments. Scroll down to the part labeled “Source File”, which is there on almost every Codex entry. Click the accompanying link. And there you are. Sometimes (usually) the line number in the Codex entry is wrong though. Now you can happily go about hacking Core files and causing yourself no end of pain and heartache.

If you look at that function, you probably won’t see what you expect anyway. The function invokes a Walker called Walker_Comment to actually display the comments. You need to look further down the source of the same file to find that Class. That is what actually displays the comment list. The start_el method is what displays individual comments.

Now, back up and take a look at the wp_list_comments default arguments:

$args = array(
    'walker'            => null,
    'max_depth'         => '',
    'style'             => 'ul',
    'callback'          => null,
    'end-callback'      => null,
    'type'              => 'all',
    'reply_text'        => 'Reply',
    'page'              => '',
    'per_page'          => '',
    'avatar_size'       => 32,
    'reverse_top_level' => null,
    'reverse_children'  => '',
    'format'            => 'xhtml', //or html5 @since 3.6
    'short_ping'        => false // @since 3.6
);

Notice that style parameter. One possible value is div. That may be all you need. If not, and you need something more complex, you may need to create a new Walker to extend Walker_Comment and pass that in as 'walker' => new My_Custom_Walker_Comment. Those sound like the two proper solutions to this. Hacking Core files is not wise.

An example of a very simple walker is here, without knowing what you want exactly it is not possible to write one specific to this case.

Attribution
Source : Link , Question Author : user1627363 , Answer Author : Community

Leave a Comment