Remove the Website/URL field from GeneratePress comments

If you want to remove the website field from your GeneratePress comment form, you’ve come to the right place. Removing this field is a bit tricky in GeneratePress but easily done with this code snippet.

Most WordPress themes enable the Website/URL field by default, but in my experience it’s just attracts spammers without adding any real value to your comment section. That’s why I remove it on all my websites.

By removing the URL field and adding quality anti-spam plugin like AntiSpam Bee, I was able to reduce my comment spam by more than 99%.

How to remove the Website Field (URL)

Because of the way GeneratePress works, the standard WordPress snippet won’t work. Instead, you have to wrap this code inside a GeneratePress hook to make sure it fires at the correct time (after the theme is loaded).

Methods:

  1. PHP Snippet (preferred)
  2. Plugin (if you’re scared of PHP)
  3. CSS (basically useless)

Remove the URL Field from GeneratePress comments with PHP

Here is the code snippet to remove the Website/URL field from every comment form:

// action hook that fires the filter after Generatepress is loaded add_action( 'after_setup_theme', 'tu_add_comment_url_filter' ); function btw_add_comment_url_filter() { add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 ); } // filter to remove the URL field function btw_disable_comment_url($fields) { unset($fields['url']); return $fields; }
Code language: PHP (php)

Where to put the PHP?

There are a couple good places to add this PHP code to your site:

  1. functions.php
  2. Code Snippets Plugin
  3. Hook Element (for advanced control)

Functions.php — The most common method is to past this code into the GeneratePress functions.php file, which you can access from Appearance > Themes > Theme Editor.

If you’re using a GeneratePress child theme, make sure to place the code in the child’s functions.php instead of the parent theme.

Code Snippets Plugin (recommended) — My preferred method is to use the free code snippets plugin, which lets you organize and run individual blocks of PHP code, with less risk of getting the White Screen of Death (if your code has an error).

GeneratePress Hook Element — If you need to only disable the URL field on specific posts or categories, you can use the GeneratePress Hook Element (GP Premium required).

If using GP hooks, the code is a bit different (see below).

Removing the URL field via GeneratePress Hook Element

  1. Go to Appearance > Elements > Add New Element
  2. Select Hook as the element type
  3. Hook: Choose Custom Hook (last option in dropdown)
  4. Custom Hook Name: after_setup_theme
  5. Execute PHP: Yes (checked)
  6. Paste the code shown below:
function btw_add_comment_url_filter() { add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 ); } function btw_disable_comment_url($fields) { unset($fields['url']); return $fields; }
Code language: PHP (php)

Basically we’re using the original code snippet except for the first add_action line, which is being handled by the Elements module instead.

  1. Set your display rules

Then, just set your Display Rules (to control which posts this code will run on). Then save and activate the hook.

Remove the URL field with a plugin

This is a super-clean and easy solution as long as you don’t need granular control over which pages the field will be removed on. If you do, use the hook method (above).

Just install this plugin: Remove URL field from GeneratePress comment form

The plugin is incredibly lightweight and doesn’t add much more code than the snippet above, so it shouldn’t affect pageload times at all.

Hide the URL field with CSS (not recommended)

This method is mostly worthless, because it hides the field from legitimate commenters, while spam bots will still be able to see it and enter text in the field.

But if for some reason you want to hide it anyway, simply add this CSS to Customizer > Additional CSS

#comments #url { display: none; }
Code language: CSS (css)

Leave a Comment