• I am developing a custom theme. I do not currently have a comments.php file, but WordPress appears to be using some sort of default for comments. I really like this one, but want to tweak a few things about it.

    How can I create my own comments.php which is basically a copy of the WordPress one?

Viewing 12 replies - 16 through 27 (of 27 total)
  • It is coming from the output of the comment_form() function.

    Here is a good primer on how this function works:
    http://ottopress.com/2010/wordpress-3-0-theme-tip-the-comment-form/

    And once you’ve gotten through that, here’s the more in-depth explanation:
    http://codex.ww.wp.xz.cn/Function_Reference/comment_form

    And here’s comment_form() in source:
    http://core.trac.ww.wp.xz.cn/browser/tags/3.1/wp-includes/comment-template.php#L1509

    That should give you an idea of what you need to filter to change the text.

    That text is coming from the ‘comment_notes_before’ key in the $defaults array, which you can filter.

    Here’s the default:

    'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>'

    You can change this, by adding an arguments array to pass to the call to comment_form(), for example (note: untested):

    $mytheme_comment_form_args = array(
      'comment_notes_before' => '<p>Change this to whatever you want...</p>
    );
    comment_form( $mytheme_comment_form_args );

    Note: the $required_text is:

    $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );

    I’ll do some digging to see if that can be modified.

    Thread Starter mrtsherman

    (@mrtsherman)

    Thanks, I now understand how comment_form works. I’m not sure if I am a big fan of this display system verse what the deprecated system. It is difficult to modify the form using an argument array if you are not intimately familiar with the form and its html. Although the old system is harder to maintain, I think it is far easier to modify because you can visually see the markup and where things are coming from.

    It does take some getting used to, but ultimately, it is a lot more powerful!

    If you run into any difficulties modifying to suit your needs, just ask away here.

    Thread Starter mrtsherman

    (@mrtsherman)

    In regards to wp_list_comments. I want to modify the actual comments display heavily. Not just CSS, but content. From my installation I can see that this function interacts with comment-template.php from wp-includes directory. Is modifying this also a no-no? If so, what is the proper way to modify the display of posted comments?

    Create a custom callback for wp_list_comments:
    http://codex.ww.wp.xz.cn/Function_Reference/wp_list_comments

    Thread Starter mrtsherman

    (@mrtsherman)

    Thank-you esmi

    Thread Starter mrtsherman

    (@mrtsherman)

    For comment_reply_link -> How do I change the actual link. For example instead of having the default which is:

    <a class="comment-reply-link" href="/hello-world/?replytocom=1#respond" onclick="return addComment.moveForm(\"div-comment-1\", \"1\", \"respond\", \"1\")">Reply</a>

    I want to add

    • Additional Class
    • Wrap ‘Reply’ with span tags
    Thread Starter mrtsherman

    (@mrtsherman)

    Solved adding the span tags. Just used reply_text param for comment_reply_link. Totally stuck on the additional class thing though.

    What are you trying to accomplish (i.e. with the style) by adding an additional class?

    Thread Starter mrtsherman

    (@mrtsherman)

    I have an existing class which styles links as buttons. This is pulled in from an external stylesheet. I know alternatives are to add the reply button class to the third party stylesheet (have to ask them) or to copy the styles over into the wordpress installation, but I would prefer to keep special cases to a minimum.

    Thread Starter mrtsherman

    (@mrtsherman)

    Could I use apply_filter? If so, what tag do I use to hook into the reply-to link?

Viewing 12 replies - 16 through 27 (of 27 total)

The topic ‘Copy default WordPress comments code’ is closed to new replies.