Support » Plugins and Hacks » [Resolved] changing comment textarea placeholder

[Resolved] changing comment textarea placeholder

  • I want to moddify the default text in the comment textarea to be the same as the comment label, though I can not find out how. Changing comment_field in the args section didn’t help (I have succesfully changed ‘logged in as’ though).

    I have solved it (as a test) by changing the following function in comment_functions.php:

    public function comment_field_label_filter($comment_html) {
    		return preg_replace('/(<label.*>)(.*)(<\/label>)/i', '${1}'.$this->options->get('cgb_form_comment_label').'${3}', $comment_html, 1);


    public function comment_field_label_filter($comment_html) {
    		$comment_html = preg_replace('/(placeholder=")(.*)(")/i', '${1}'.$this->options->get('cgb_form_comment_label').'${3}', $comment_html, 1);
    		return preg_replace('/(<label.*>)(.*)(<\/label>)/i', '${1}'.$this->options->get('cgb_form_comment_label').'${3}', $comment_html, 1);

    This is, ofcourse, ugly and will break at the next plugin update.

    Is there a way to simulate this without editing the plugin directly? I didn’t get it to work with a filter yet. Editing my functions.php with a hardcoded replacement for the placeholder would be okay for me, but I preferably either copy the text from the label or have another input field for the placeholder on the plugin page.


Viewing 2 replies - 1 through 2 (of 2 total)
  • ofcourse the placeholder preg_replace should have been:
    $comment_html = preg_replace('/(placeholder=")(.*?)(")/i', '${1}'.$this->options->get('cgb_form_comment_label').'${3}', $comment_html, 1);

    Plugin Author mibuthu


    I now had a look at this but I think that changing the placeholder texts is a very special thing that is not required by many users. So I decided not to implement a separate option for that.

    But you can still get your result by use of the “Comment form args” option.
    If you define the required html code for the comment_field you can set the placeholder to your requirements, e.g.:
    array('comment_field' => '<p class="comment-form-comment"><label for="comment">'._x('Comment', 'noun').'</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="placeholder"></textarea></p>')

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] changing comment textarea placeholder’ is closed to new replies.