Back to home

Remove the ‘Website’ field from the WordPress comment form

Table of Contents

Introduction

The default WordPress comment form contains the following fields:

  • Comment
  • Name
  • Email
  • Website
  • Accept Cookies
A screenshot of the default WordPress comment form with comment, name, email, website, and cookie input fields.

I’m not a fan of the website field, especially since it’s optional anyway. As such, I like to remove it from my blogs.

Remove the Website Field

This code snippet uses the comment_form_default_fields hook to remove the url field from the $fields array. Place this in either your theme, child theme, or a custom plugin.

/**
 * Removes the website field from the comment form
 */
function removeCommentWebsiteField( array $fields ): array
{
    if (isset($fields['url'])) {
        unset($fields['url']);
    }
    return $fields;
}
add_filter('comment_form_default_fields', 'removeCommentWebsiteField');
A screenshot of the WordPress comment form with comment, name, email, and cookie input fields. The cookie field still mentions the website input which is missing.

Now that the Website field is gone, the text for the cookie acceptance input needs to be updated to omit the website word website. This function uses the comment_form_fields hook to replace the text with a custom string. Place this alongside the previous code you added.

/**
 * Reorders the comment form field to be the second-to-last element
 */
function changeCookieFieldText( array $fields ): array
{
    if (!isset($fields['cookies'])) {
        return $fields;
    }

    // Set to whatever you like. This is the default message withou the website field.
    $defaultText = 'Save my name, email, and website in this browser for the next time I comment.';

    if (str_contains($fields['cookies'], $defaultText)) {
        $fields['cookies'] = str_replace(
            $defaultText,
            'Save my name and email in this browser for the next time I comment.',
            $fields['cookies']
        );
    }       
    return $fields;
}
add_filter('comment_form_fields', 'changeCookieFieldText');
A screenshot of the WordPress comment form with comment, name, email, and cookie input fields. The cookie input field no longer mentions a website field.

Re-order the Fields

If all you wanted to do was remove the Website field, then you’re done. However, as one last touch, I also like to move the Comment field to be the last text input, as it makes more sense to me that a user enters their details before their comment. This function uses the comment_form_fields hook to move the comment input to go before the cookie acceptance input.

/**
 * Reorders the comment form field to be the second-to-last element
 */
function reorderCommentFields( array $fields ): array
{
    if (!isset($fields['comment'])) {
        return $fields;
    }
    
    // Save the comment field, and unset it from its default position
    $commentElement = ['comment' => $fields['comment']];
    unset($fields['comment']);

    $keys = array_keys($fields);

    // Find the cookies field, and insert the comment field before it
    if ($pos = array_search('cookies', $keys)) {
        return array_merge(array_slice($fields, 0, $pos), $commentElement, array_slice($fields, $pos));
    }
    
    // If the cookies field doesn't exist, put the comments at the end as a default
    return array_merge($fields, $commentElement);
}
add_filter('comment_form_fields', 'reorderCommentFields');
A screenshot of the WordPress comment form with name, email, comment, and cookie input fields.

Related blogs

  • wagtail-page-querying
    Efficient parent/child page querying in Wagtail

    In Wagtail, pages exist within a hierarchical system, where each page has a single parent and potentially several children. The method of storing the page’s hierarchical ‘location’ in the database is slightly atypical.

    17 July 2025
  • wagtail-scheduled-publishing-modal
    Wagtail no scheduled publishing option

    Wagtail supports scheduling a page’s publication date and time out of the box. The first time I tried to use this feature, I lost a lot of time to an issue where the expected ‘Set schedule’ button wasn’t displaying in the page’s ‘Status’ tab.

    3 July 2025
  • wagtail-seo-opening-times-week-demo
    Using wagtail-seo hours of operation in templates

    wagtail-seo comes with various SEO settings for your site, including fields for ‘Hours of operation’. I needed to take this data and output it on a template in a nice format. This approach is minimal and effective, so if you are also looking to build a global opening hours widget, …

    16 May 2025