WordPress.org

Forums

change position of field label for comment form fields (3 posts)

  1. hp3
    Member
    Posted 4 years ago #

    I would like to change the formatting of the comments form. I am using a theme based upon twentyten, which displays the label of a form element to the left of the form element.

    ex.
    Email * [email form element]

    Instead I want to display the label for the form element to the right of the form element.

    ex.
    [email form element] Email *

    I assume I would use the $fields array to specify the HTML for each form element and somehow pass that to the comment_form() but I don't how to do this.

    How do I accomplish this?

  2. Tommie Hansen
    Member
    Posted 4 years ago #

    Just edit your comments template found under yoursite.com/wp-content/themes/YOUR-THEME/comments_template.php

    ..or what it is called. Been 5 months since i created a theme. :-)

    [signature removed per forum etiquette]

  3. hp3
    Member
    Posted 4 years ago #

    Thanks for the suggestion. I wanted to avoid building a new template just for the form and rely on a programmatic solution.

    I was able to use a filter to change the position of the label tag for the email and author fields. However the required mark no longer displays for these two fields.

    The documentation for the comment_form() under $fields uses a $req variable. I am not sure if this is a legit wordpress variable or just something in the example.

    I copied these example form element HTML strings, but the $req variable is probably not correctly used in my code. I tried using global in my filter function but that did not fix the problem.

    ex.

    function modify_form($updated_fields){
    global $req;
    $updated_fields['author'] = 'revised html' . ( $req ? '<span class="required">*</span>' : '' );
    $updated_fields['email'] = 'revised html' . . ( $req ? '<span class="required">*</span>' : '' );
    return $updated_fields;
    }
    add_filter('comment_form_default_fields', 'modify_form');

    How do I know if a field is required?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.