Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Nipon on "Adding placeholders in comments form"

$
0
0

I added placeholders to the comment form using the following code in comments. php and it works just fine.

<?php
	$comments_args = array(
        // change the title of send button
        // 'label_submit'=>'Send',
        // change the title of the reply section
        // 'title_reply'=>'Write a Reply or Comment',
        // remove "Text or HTML to be displayed after the set of comment fields"
        'comment_notes_after' => '<p><small>Your comment may be subject to editorial review.</small></p>',
        // redefine your own textarea (the comment body)
        'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true" placeholder="Type your comment here..." rows="8" cols="37" wrap="hard"></textarea></p>',
		'fields' => apply_filters( 'comment_form_default_fields', array(

    'author' =>
      '<p class="comment-form-author">' .
      '<input id="author" placeholder="Your name..." name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
      '" size="30"' . $aria_req . ' />' . ( $req ? '<span style="color:red" class="required">*</span>' : '' ) . '</p>',

    'email' =>
      '<p class="comment-form-email">' .
      '<input id="email" placeholder="Your email..." name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
      '" size="30"' . $aria_req . ' />' . ( $req ? '<span style="color:red" class="required">*</span>' : '' ) . '</p>',

    'url' =>
      '<p class="comment-form-url">' .
      '<input id="url" placeholder="Your website..." name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
      '" size="30" /></p>'
    )
  ),
);
	comment_form($comments_args); ?>

However, according to the Codex, I must set the variables (present in the above code) within my callback using the following code - which I did not do.

$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );

Where do I exactly place the above code? The output, by the way, is just fine i.e. I can see the placeholders in the comment form alright.


Viewing all articles
Browse latest Browse all 8245

Trending Articles