My site requires users to login to comment. Unregistered and logged out users see "Must be logged in to comment. You may also register for an account."

How do I change this text and the links?

Saw this old post, but that doesn't work: How to change "You must be logged in to post a comment."

Ultimately, I'd like to make these bring up popup forms, so users aren't diverted away from the page.

Or is there a better solution to make this happen, like somehow hiding the text altogether and showing a login form (in a block) for unregistered/logged out users only?


  • if you use a plugin like wpdiscuz to make the comment form then things will be much easier. Commented Jul 23, 2021 at 14:27
  • I have a rating/review plugin for comments. Exactly how would WPDiscuz make things easier?
    – SCYankee
    Commented Jul 23, 2021 at 15:17

1 Answer 1


The text, "You must be logged in to post a comment." comes from this line in WordPress: https://github.com/WordPress/WordPress/blob/efaf4a8938bbeb8510c8e1e4cc6fe84a434c17c3/wp-includes/comment-template.php#L2449

Whenever you see something wrapped in the double underscore function __( ), it means it's a translatable string.

You can use a function like this and add it to your themes functions.php file:

add_filter('gettext', 'change_comment_logged_in_notice', 20, 3);
 * Change the text for needing to be logged in to post a comment
function change_comment_logged_in_notice( $translated_text, $untranslated_text, $domain ) {

    switch( $untranslated_text ) {
        case 'You must be <a href="%s">logged in</a> to post a comment.':
            $translated_text = __( 'You need to <a href="%s">log in</a>' );
   return $translated_text;

More info on the gettext filter: https://developer.wordpress.org/reference/hooks/gettext/

Alternatively, you can use a plugin like Loco Translate which let's you view strings that are translatable and let's you translate them in an interface: https://en-ca.wordpress.org/plugins/loco-translate/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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