0

In my code, comment_notes_before doesn't show anything.

<?php
$args = array(
    'class_form'      => 'add_review',
    'label_submit'      => __( 'Leave a review' ),
    'comment_notes_before' => 'Before',
    'comment_field' =>  '<textarea id="review_text" name="comment" placeholder="Enter your review"></textarea>',
    'comment_notes_after'  => 'After>',
    'logged_in_as' => ''
);
comment_form($args);

Is there a problem in my code?

3
  • Did you check when you're logged out?
    – birgire
    Feb 9 '17 at 13:34
  • Yes, I'm logged in
    – M. Monica
    Feb 9 '17 at 13:43
  • 1
    This is only displayed if you're logged out.
    – birgire
    Feb 9 '17 at 14:19
1

As noted by @birgire, the comment_notes_before argument is only shown to users who are not logged in. If you look at the source, there is an if construct that checks if a user is logged in. If they are logged in, then a filter and an action fired. If not, then the comment_notes_before text is echoed.

If you want to show the before text to users logged in, you can use one of those hooks and echo the before content.

<?php
$before = 'Before';

//* Show $before only to logged in users
add_action( 'comment_form_logged_in_after', 'wpse_106269_logged_in', 10, 2 );
function wpse_106269_logged_in( $commenter, $user_identity ) {
  echo $before;
}

$args = array(
  'class_form'      => 'add_review',
  'label_submit'      => __( 'Leave a review' ),
  'comment_notes_before' => $before, //* Only shows for logged out users
  'comment_field' => 
    '<textarea id="review_text" name="comment" placeholder="Enter your review"></textarea>',
  'comment_notes_after'  => 'After',
  'logged_in_as' => ''
);
comment_form($args);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.