Privacy PHP Beginner

Remove the Website Field From Comments

Remove the Website field from the comment form and ignore any website address that's sent anyway, reducing personal data and link spam.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 12 lines
add_filter( 'comment_form_default_fields', function ( array $fields ): array {
	unset( $fields['url'] );
	return $fields;
} );

// Bots post the field even when it isn't on the form.
add_filter( 'preprocess_comment', function ( array $comment ): array {
	if ( ! is_user_logged_in() ) {
		$comment['comment_author_url'] = '';
	}
	return $comment;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

The Website field collects data you probably don’t need, and it’s the main reason spam bots post comments: to get a link. Removing it cuts both.

How it works

comment_form_default_fields lists the fields shown to logged-out visitors. Removing url takes the Website box off the form.

Spam bots don’t use the form; they post straight to WordPress. preprocess_comment clears any website address from new comments by logged-out visitors, so links are never saved.

Things to watch

  • Existing comments keep their website links. Remove them in bulk with a database query if needed.
  • Logged-in users’ comments use the website from their profile.

How to test it

Log out and view a post. The comment form should have only Name, Email and Comment.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only