[Resolved] Comment form: Add URL label but keep placeholder

Home Forums Support [Resolved] Comment form: Add URL label but keep placeholder

Home Forums Support Comment form: Add URL label but keep placeholder

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1508292
    George

    I want to add a URL field label but also keep the placeholder text on the URL field, like in the example provided. Is this possible?

    #1508533
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could try this:

    add_filter( 'comment_form_default_fields', function( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['url'] = sprintf(
            '<label for="url">%1$s</label><input placeholder="%1$s" id="url" name="url" type="url" value="%2$s" size="30" />',
            esc_html__( 'Website', 'generatepress' ),
            esc_attr( $commenter['comment_author_url'] )
        );
    
        return $fields;
    } );
    #1508541
    George

    Perfect, it works, had to raise the priority:

    add_filter( 'comment_form_default_fields', function( $fields ) {
        $commenter = wp_get_current_commenter();
    
        $fields['url'] = sprintf(
            '<label for="url">%1$s</label><input placeholder="%1$s" id="url" name="url" type="url" value="%2$s" size="30" />',
            esc_html__( 'Website', 'generatepress' ),
            esc_attr( $commenter['comment_author_url'] )
        );
    
        return $fields;
    }, 20 );

    Thanks, Tom!

    #1509883
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

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