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

WordPress logoAs 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 (link now dead). 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!)

About gerardmcgarry

Gerard is a web designer, blogger and web publisher. He’s one of the founders of the enormously popular UK reality TV blog, Unreality TV and is currently developing its sister site Unreality TV USA.

22 comments

    1. 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

  1. 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. :)

  2. 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.

    1. It will not technically stop the spam. But it can make it trivial to catch almost all spam.

      On my blog, 100% of my spam fills in the ‘URL field’.

      If I disable the URL field in comments.php, then I *know* with 100% certainty that any comment which fills in the URL field is spam. Why would a human send POST requests? :P

      So I can set a simple rule that automatically deletes any comment that contains a URL in the URL field.

  3. I want to keep the URL field and just make it “fake” so the spammers post their url and it simply never shows up on the front end.

    Why? because the spammers comments are getting more legible each passing year and I want to collect them to make my blog look good. I’ll eventually delete them later on once I have traffic, but might as well abuse te abusers here.

  4. 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

  5. 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.

  6. I’m using the Generate child theme in Genesis and this worked fine for me. The code snippets provided by StudioPress didn’t work – so thanks a bunch for posting this!

  7. The comment field has physically been removed from the template AND we’ve used the function as mentioned above to remove it. Yet spam comments till appear with url’s submitted – welcome to the twilight zone (which is very annoying)!

  8. This is great. Thanks for the tip. It’s ironic that you didn’t do the same thing to this website, but I’m just happy to have it gone from my site.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>