8

In an effort to combat comment spam, I'd like to hide or remove the "Website" field from the "Leave a Reply" section for page and site comments.

I have no desire to increase others page rankings by having them embed their URLs in my sites comments, which seems to be what 99% of the comments on my site are wanting to do.

I'm using the Twenty Ten theme if that makes any difference in the answer.

Thanks!

1
  • Why not use Akismet and/or captchas?
    – Raphael
    Commented Nov 18, 2010 at 13:50

4 Answers 4

13

Create a file in wp-content/plugins/ with this code:

<?php
/*
Plugin Name: Get Rid of Comment Websites
*/
function my_custom_comment_fields( $fields ){
  if(isset($fields['url']))
    unset($fields['url']);
  return $fields;
}

add_filter( 'comment_form_default_fields', 'my_custom_comment_fields' );

Normally, I'd say put it into your theme's functions.php file, but I wouldn't recommend doing that for a theme that could update like Twenty Ten. This way will let you add this functionality as a plugin which can be disabled.

6
  • That did the trick - thanks! Created a folder called "remove-url-field" and created a file inside it called "remove-url-field.php" and then went and activated the plugin that showed up in the Plugins interface. Quick and easy!
    – cpuguru
    Commented Oct 22, 2010 at 16:51
  • 2
    For simple plugins like the above it's not necessary to create a folder, a standalone file will work just fine.. (ultimately it's your choice of course, just pointing out it's not a requirement for plugins).
    – t31os
    Commented Nov 18, 2010 at 15:59
  • Is this really the simplest way? It seems odd that there are options in the admin for "Comment author must fill out name and e-mail" for example, but not to hide the Website field. Commented Aug 3, 2011 at 23:21
  • What is complicated about this? If you don't want to deal with FTP, I'm sure you could find something in the plugins repo that would do this. Commented Aug 4, 2011 at 14:51
  • 1
    @MD004 Closing the PHP tag is not required at the end of a file. In some cases it can even prove detrimental, as some editors will silently append a newline at the end of the file, which will send the newline to the browser as the first part of the response body. This becomes very bad when you need to send custom headers later than plugins loading, or when XML expects the correct text to be the first text in the document, not a newline. Commented Mar 14, 2019 at 17:25
0

Apart from the good answer by John, I use a more straight forward solution, that allows me more control over the comment form and its fields.

By default, your theme's comments.php (Twenty Eleven's, for example) may have something like this — <?php comment_form(); ?>

Now, using <?php comment_form(); ?> is the same as:

<?php
    $args = array(
        'fields' => array(
                        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                                        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
                        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                                        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
                        'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
                                        '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
        );
    );
    comment_form( $args );
?>

The only difference, AFAIK, is that the longer version gives you more flexibility. As in your case, you don't want to show the website field. So, you simply remove the url parameter in the fields array, and the end result is this:

<?php
    $args = array(
        'fields' => array(
                        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                                        '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
                        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
                                        '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
        );
    );
    comment_form( $args );
?>

...which is what you need.

Recommended Reading: WordPress Codex Function Reference / comment_form

Source File: (trunk version — most current) http://core.svn.wordpress.org/trunk/wp-includes/comment-template.php

0

Not a perfect solution, the other solutions are fine

Instead of modifying PHP, comments form, any how it's just one input field, whats there if it is load and hided, Instead of writing if statements or rewrite the comments form

simply hide the URL field

.comment-form-url {
    display: none;
}
0

Removing the website field from comment form is quite easy. Below is the code with is just of few lines:

function cs_remove_comment_website_fields($fields) {
  unset($fields['url']);
  return $fields;
}
add_filter('comment_form_default_fields','cs_remove_comment_website_fields');

Source: How to remove the website field from WordPress comment?

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