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?

  • Why a downvote? Explain it please... – user1627363 Jul 1 '13 at 14:29
  • You're getting downvoted because your question, basically, is the wrong kind of question. You're asking "where is X so that I can make a change to it", when you should be asking "I want X to behave in this way (example provided), how do I make it do that?" More information about your desired outcome will get you a better and more thorough answer than a question about how to do something which is obviously wrong (editing core code to affect a change to output). – Otto Jul 1 '13 at 17:53
  • 1
    In other words, there's never a good reason to change wp_list_comments or any of the code beneath it, because it is possible to pass various parameters to it to make it behave in pretty much any way desired. And that includes completely changing the code, via callback functions or giving it custom walker classes. – Otto Jul 1 '13 at 17:58

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.