[Resolved] Comment form required fields to anonymous posting

Home Forums Support [Resolved] Comment form required fields to anonymous posting

Home Forums Support Comment form required fields to anonymous posting

  • This topic has 5 replies, 3 voices, and was last updated 4 years ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1248655
    Rogi

    Hi guys.

    I want anonymous comments to be posted on my blog.
    In the discussion settings, I unchecked the option to require filling in name and email.
    But the required field asterisk still appears in the comment form.

    Thanks in advance.

    #1248944
    David
    Staff
    Customer Support

    Hi there,

    add this PHP Snippet to your site:

    add_action( 'after_setup_theme', 'tu_add_comment_url_filter' );
    function tu_add_comment_url_filter() {
        add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 );
    }
    
    function tu_disable_comment_url($fields) {
        unset($fields['url']);
        unset($fields['email']);
        unset($fields['name']);
        return $fields;
    }

    https://docs.generatepress.com/article/remove-e-mail-and-url-field-from-comment-form/

    #1249057
    Rogi

    Hi David,

    First, thanks for the quick response.
    I don’t want to remove the url and email fields.
    I just want the required field asterisk not to appear (in the name and e-mail fields).
    This code that you recommended removed the URL and Email fields…

    Thanks.

    #1249567
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this instead:

    add_filter( 'comment_form_default_fields', function( $fields ) {
    	$commenter = wp_get_current_commenter();
    
    	$fields['author'] = sprintf(
    		'<label for="author" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="author" name="author" type="text" value="%2$s" size="30" />',
    		esc_html__( 'Name', 'generatepress' ),
    		esc_attr( $commenter['comment_author'] )
    	);
    
    	$fields['email'] = sprintf(
    		'<label for="email" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="email" name="email" type="email" value="%2$s" size="30" />',
    		esc_html__( 'Email', 'generatepress' ),
    		esc_attr( $commenter['comment_author_email'] )
    	);
    
    	return $fields;
    }, 20 );
    #1249722
    Rogi

    Tom,

    Now it worked!

    Thank you very much for your help!

    Igor

    #1250050
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.