• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Modify Comment Form Default Fields

Recently i was hired by a web designer to provide custom coding for their clients comment form.

The client wanted to change the order of the input fields, remove the website URL field and add 2 custom comment form fields named Title and Industry.

Here’s the result i achieved without hacking the WordPress core files and using 3 custom functions to filter the default output via a child theme:

custom comment form fields

And here’s the code i used to remove the default fields and return the custom fields in the order in the code which also includes 2 small functions to filter 2 of the comment form titles and modify the comment form button text.

Once the custom fields have been generated for the front end, there’s more code needed to save the custom data in the database and display it in different admin pages.

Comments admin

You can also display the data in the comment form on the front end.

Removing Fields

You can use the built in filters to remove fields.

This example removes the website URL field:

add_filter('comment_form_field_url', '__return_false');

This example removes the email field

add_filter('comment_form_field_email', '__return_false');

This example removes the name field

add_filter('comment_form_field_name', '__return_false');

Or you can use this code to unset each field:

add_filter( 'comment_form_default_fields', 'remove_comment_form_fields' );
function remove_comment_form_fields( $fields ) {
    unset($fields['author']);
    unset($fields['email']);
    unset($fields['url']);
return $fields;
}

Note: Removing fields may cause a problem if they are required*.

Notes

Non Genesis users will need to remove the second custom function which includes the genesis_title_comments filter.

Comments

Reader Interactions

Comments

  1. Andrew Hateley-Browne says

    June 4, 2018 at 3:44 pm

    I want to do something similar to this, but apply the changes to one category only. I assume I use the if(has category()) function but I haven’t been able to make it work.

    Log in to Reply
    • Brad Dalton says

      June 4, 2018 at 6:01 pm

      Use in_category.

      https://codex.wordpress.org/Conditional_Tags#A_Category_Page

      Log in to Reply
  2. Swag says

    March 2, 2018 at 7:14 am

    Hello Brad,
    Thanks for this useful code!
    If I modify my genesis theme with this code, will it help to enhance the comments with improved SEO feature?
    I have tons of comments in my site and have been looking ways to include a meta box in the comments and in the front end edit, which mightl hopefully help to enhance the existing wordpress comment system with better seo response.
    Kindly clarify this doubt, will greatly appreciate your expert view on this.

    Log in to Reply
    • Brad Dalton says

      March 2, 2018 at 5:12 pm

      I doubt it however comments which add value for the readers of your post might boost your rankings and make the post more popular.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.