WordPress: How to remove the website field from the comment form

February 4, 2011
By Zee

For my purposes, I did not see any real benefit from having users leave a website URL (it didn’t help that it was being used by spammers). I decided to remove the ‘Website’ field from the WordPress comment form. A quick search of the files through the Appearance editor didn’t yield anything obvious regarding where the fields were actually listed so a function must be called which pulls in the default comment fields. The function is located within one of WordPress’s core files and is named ‘comment_form’. Instead of modifying this function, I will first show you the best way to remove the website field.

We’re going to create a plugin to filter out the website field from the comments form. This is the ideal method to remove the website field since you won’t have to worry about modifying a theme or core file which may change.

1. Navigate to your /wp-content/plugins/ directory and create a file named urlfilter.php. You can create and modify the file using your web hosts file manager or ssh account. Alternatively, you can create the file locally and upload it via ftp or through your web hosts file manager. Notice the majority of plugins have their own folders here, however, you do not need to create a folder for this plugin.

2. Place the following within the contents of the file urlfilter.php:

<?php
/*
Plugin Name: Remove Website Field
Description: Removes the website field from the comments form
*/
add_filter('comment_form_default_fields', 'url_filtered');
function url_filtered($fields)
{
  if(isset($fields['url']))
   unset($fields['url']);
  return $fields;
}
?>

3. Save your changes. If you modified the file directly through your web hosts file manager or SSH account then you’re set. If you created the file locally you will need to upload it via FTP or through you web hosts file manager to the /wp-content/plugins/ directory.

4. Go to the Plugins menu and you will now see a plugin named Remove Website Field. Enable the plugin by clicking on the ‘Activate’ link under the plugin name. The ‘Website’ field has been successfully removed from your comment form and no one will see it anymore.


In case you are curious, the following method will also remove the website field but it requires modifying a core WordPress file. This is not recommended since these are considered sensitive files. Additionally, you would have to modify the core file each time you upgrade WordPress.

You’ll need to modify the core WordPress file named ‘comment-template.php’ located within the ‘wp-includes’ directory. To modify this file I did so through my web hosts file manager. You can also access the file through your ftp or ssh account if you have one. Before doing anything, make sure to BACKUP the file so you can revert to your original copy if need be. You MUST modify the file with a plain text editor and NOT a word processing program as they can break your code.

How to remove the website field from the comment form by editing the /wp-includes/comment-template.php file:

1. Search for the following within the file, it’s located near the end.

'url'    =>

2. You should end up at the following:

1
2
'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>',

3. Place two forward slashes before each line to comment them out:

1
2
// '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>',

4. Save your changes. If you modified the file directly through your web hosts file manager or via SSH then you’re set. If you downloaded it via FTP or file manager and saved the changes locally, you will have to overwrite/replace the old one.

The ‘Website’ field has been successfully removed from your comment form and no one will see it anymore.

NOTE: There are other ways to remove the website field which I didn’t explore and there are other means to stop spam such as using a plugin. I may review such plugins sometime in the future.

Related Posts:

Tags: ,

35 Responses to “WordPress: How to remove the website field from the comment form”

  1. Wouter says:

    Nice and very clean solution. I never really thought about this, but I can see myself using these custom written plugins a lot more often in the future.

  2. Jason says:

    I love the idea and found your post looking for this exact thing, but for some reason it isn’t working on my site. I made the php file, uploaded it, activated the plugin, but the website field is still there. Any suggestions, would be greatly appreciated!

  3. Suresh Khanal says:

    Most probably this is the first time I’m commenting on a form that does not have website field. Its funny. But I reached your post through search engine as I had to remove URL field out form my comment form. I don’t need it in my blog ICT Trends.

    Thanks for the good post and the method worked great for me!

  4. Angelo Bertolli says:

    Wow, if it’s that easy I wonder why there isn’t just a checkbox for it in the dashboard… :/

  5. Der Applejünger says:

    Thank you very much!!! :-)

  6. Kostas R says:

    THanks for the article. The method of your comment just removed the field but left the label there, so its weird. My label’s name is “Website:” . Is there an easy way to remove that too?

  7. Christian fudge says:

    Thanks for this information! I was just about to edit the comment.php file when I came across this post! Very simple to do and works like a charm!

  8. Sander Kriek says:

    {display:none;}, fantastic!

  9. robert says:

    what would i change in your urlfilter.php file if i also want to remove the email field as well?

  10. Sherri says:

    I am very new to the whole website building; so I have been very reluctant to change any of the .php files. But just inserting “//” was very straight forward and EASY! Thank you!

  11. Alex says:

    hI guys,

    i cant find the #commentform in my style css.

    i have the twenty ten template.

    Any ideas?

  12. john gullo says:

    Is not working with WordPress 3.1.3

  13. Anon says:

    This is great. I’ve been looking for a way to eliminate spam comments. This almost does the trick, however spambots can still send a post query to your wp-comments.php file with a URL. What I’ve done is put the following line at the top of wp-comments.php

    if(!empty($_POST['url'])){
    exit;
    }

    Now if anyone tries to submit a URL, its spam and the comment will be entirely blocked. You will also want to set your discussion options to moderate any comments that contain one or mor links within the comment text itself.

  14. Martin says:

    Superb! Thank you Zee. I added the .php file as above via file manager and it worked – straight out of the box. :)

  15. Rajkumar says:

    A Great and Very Good Solution.

    Thank You

    Raj

  16. Klevis Miho says:

    Nice and clean solution, thank you.

  17. shaguna says:

    The plugin method worked like a breeze. You also made me realize how simple creating a plugin is!
    Thanks :)

  18. michael says:

    Thank you for this!

  19. khalil says:

    Superb! thanks a lot!

  20. John says:

    That worked beautifully! Thank you very much. oops, I clicked on one of your ads…….. =) well deserved

  21. Kril says:

    Good stuff, you can also achieve the same effect by adding this code to functions.php of your theme

    • Brad Trivers says:

      Yes – thanks. Couldn’t figure out this filter using the codex documentation! I just added it to my function.php file too.

  22. Matt says:

    Great Solution! Simple to set up and the plugin won’t get changed in an update.

  23. RAVI SHANKAR SINGH says:

    11636224

  24. Josh Lutton says:

    The plug-in method worked great for me. Thanks for the useful info.

  25. Scott D. says:

    Your plugin is an easy and elegant solution. Pasted your code into a text document and uploaded through ftp to plugin folder. Worked like a charm. Thank you so much!

Trackbacks/Pingbacks

  1. Tweets that mention Wordpress: How to remove the website field from the comment form | TechHacking.com -- Topsy.com
  2. How To Remove Website Field From Comment Form — Shariff.org
  3. The most easy and safe way to remove website or url field from wordpress comment form | SEO MMO Tips
  4. Die Website-URL aus dem Kommentarfeld entfernen
  5. Anti-Spam: Das Website-Feld entfernen
  6. WordPress: How to remove the Website URL field from the comment form | Odizajn

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Translate

EnglishFrenchGermanItalianPortugueseRussianSpanish
Hire PHP Developer India