WordPress: How to remove the Website URL field from the comment form

Wordpress - removing the comment form URL fieldAs a blogger, the URL field in the WordPress comments form is a constant pain - either spammers are using it to drop shady links, or readers feel compelled to fill it with garbage just to fill in the field. Either way, it's a nuisance. But how do you get rid of it?

Well, I spent a long time searching for the solution to this problem last night, and I've written up a solution for removing the URL field that takes into account a number of different scenarios you might encounter!

Obligatory warning! Never apply these types of changes to a production site - I keep a copy of my website themes on a testing server and make changes there. I suggest you do the same!

Before we begin

Most of the changes we'll be making will be in your WordPress theme. In my experience, there are a few different scenarios that we need to be aware of:

1. Your WordPress theme doesn't have a comments.php file

If your WordPress theme is missing the comments.php file, WordPress will use the default template, located in /wp-includes/theme-compat/comments.php. This is all well and fine, but the fix detailed below requires the comments.php file to exist in the theme directory.

To overcome this, copy the comments.php file from the folder above into your theme folder. Once you've done this, follow the next step:

2. Your WordPress theme has the comment fields inserted manually

Most modern themes will use the <?php comment_form(); ?> code snippet at the bottom of the comments.php file. If this isn't present in your comments.php file, then you should look for a line of HTML/PHP code that refers to a 'URL' field. Simply delete that line and your WordPress comments form should now be missing the website field!

In this scenario, you don't need to progress to the more advanced solution detailed below - you're all done!

3. Your theme's comments.php calls comment_form()

OK - so your comments.php file contains:

<?php comment_form(); ?>

And comments.php is located inside your theme directory? You've come to the right place! Step this way...

Remove the Website URL field

OK, open up your theme's functions.php file and add the following code to the end of the file:


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

This code snippet is from TechHacking. However, they talk about implementing it as a plugin. It's easier if you just add the code to functions.php in your theme.

Now, refresh your blog pages and the URL field should be missing from the comment form. (Aside: if the changes don't appear right away, make sure you're not running a caching plugin, and if you are, be sure to flush the cache!)

Comments for WordPress: How to remove the Website URL field from the comment form

I used option 3, but I had to insert:

add_filter('comment_form_default_fields''url_filtered');
function 
url_filtered($fields)
{
  if(isset(
$fields['url']))
   unset(
$fields['url']);
  return 
$fields;
}

inside the existing php tags, rather than open/close another php tag

Very nice solution. I used the solution posted by Jim & that worked really well. Also I wanted to add that if you are using any comment_form() function to call the comments template & you have URL input textbox in it, then you would need to delete that input as well in order for the code to work correctly.

Hope this helps someone.

Thanks - solved my problem (in my case I also had to apply it inside the existing php tags for it to work though)

YAY! thanks this worked like a champion. I appreciate all your help

Thanks for the tip!
What do I have to change in this of code to also remove the email-field?

I don't think it's possible to remove the email address field, since it's a required field in the comment form.

I already figured it out: change the code to this:

if(isset($fields['url'],$fields['email']))
unset($fields['url'],$fields['email']);

But you have to disable 'require email' in WP preferences

Works wonderful. Thanks

Thanks, worked a treat! Just added the code above to my themes function.php file, hit save and job done. No more spammy links in the URL field. :)

This would not stop the vast majority of spam. Do you think the spambots fill in the fields? They just send POST requests the server and ignore the HTML. They know its Wordpress and understand what is required to send the comment without needing to see the [input] tag for URL.

You need to remove the part where Wordpress processes the URL as well to make this truly effective.

Add new comment