How to Quickly and Easily Customize the WordPress Comments Form

Many WordPress themes utilize the standard WordPress comments form. Introduced in WordPress 3.0, it’s meant to be a simple tag to output a complete commenting form within a theme template. Making minor changes to the form might seem baffling at first, but it’s really not too difficult.

Step 1: Don’t hack the core.

Here’s the most important tip: Don’t edit the /wp-includes/comment-template.php file. Someone may have suggested it to you in the forums as the quickest way to customize the comments template, but it’s never really a good idea to edit the WordPress core files. There’s a better way.

Step 2: Edit the Comment Form Tag.

Open the file containing the comment form tag. Here’s what it looks like:

1
<?php comment_form() ?>

More than likely the theme file that you’re looking for is going to be comments.php.

There are some some different parameters you can pass to the function for modifying the form. The codex has several handy examples for editing the comments template. Let’s do a simple one.

If you want to remove the HTML text that follows the form (“You may use these HTML tags and attributes…”), here’s how to modify the tag:

1
2
3
4
5
6
7
8
9
10
<?php 
$comments_args = array(

        // remove "Text or HTML to be displayed after the set of comment fields"
        'comment_notes_after' => '',

);

comment_form($comments_args);
?>

Not so difficult, right? Now, let’s change the title of the comment form. By default it says “Leave a Reply”. Let’s change that to “Comment”.

1
2
3
4
5
6
7
8
9
<?php 
$comments_args = array(

        // change "Leave a Reply" to "Comment"
       'title_reply'=>'Comment', 
);

comment_form($comments_args);
?>

You can change the text to be something more creative than “Comment”, such as “Discuss this post” or “Have something to say?”

The codex includes several more examples, but these simple ones should be enough to get you started. You can also rest assured that these quick edits to your theme’s comments file will be safe, even when you upgrade the WordPress core.

Tags

Comments (2)

    • If you want to do it the right way, without using CSS hacks, use the following code:

      //Remove URL from comments
      add_filter('comment_form_default_fields', 'url_filtered');
      function url_filtered($fields)
      {
      if(isset($fields['url']))
      unset($fields['url']);
      return $fields;
      }

      Also make sure that you remove the HTML code for the input textbox for URL from comments.php. If you are not using one, then make a copy of WP original comments.php file & delete the code from it. Then call it using comment_form() function in loop-single.php file or wherever else you want to.

      Hope that helps.

Participate