I've got a password protected post and comments_popup_link('No Comments', '1 Comment', '% Comments'); function displays "ENTER YOUR PASSWORD TO VIEW COMMENTS." message. The question is, is it possible to change this message without touching core files, maybe apply filter or something like that. Thanks.

1 Answer 1


The only hook to change that is gettext:

add_action( 'loop_start', 'wpse_77028_switch_filter' );
add_action( 'loop_end',   'wpse_77028_switch_filter' );

 * Turn comment text filter on or off depending on global $post object.
 * @wp-hook loop_start
 * @wp-hook loop_end
 * @return  void
function wpse_77028_switch_filter()
    $func = 'loop_start' === current_filter() ? 'add_filter' : 'remove_filter';
    $func( 'gettext',    'wpse_77028_comment_num_text', 10, 3 );

 * Change default text for comments_popup_link()
 * @wp-hook gettext
 * @param   string $translated
 * @param   string $original
 * @param   string $domain
 * @return  string
function wpse_77028_comment_num_text( $translated, $original, $domain )
    if ( 'Enter your password to view comments.' === $original
        and 'default' === $domain
        return ' ';

    return $translated;

Unfortunately, this is rather expensive: gettext is called many, many times, and the filter will run each time. You cannot deactivate it after the first match, because it might be needed more than once per page. I have added a wrapper function to make sure it is running only when there is a global $post object.

  • If you think it is expensive (not sure about that) you can wrap it in a function which sets and unsets the filter. You can even check if the post is password protected before setting the filter.... Commented Dec 23, 2012 at 11:04
  • @MarkKaplun How do you test the protection? comments_popup_link() might be used outside of the main query, so you cannot rely on a global $post object. Not sure I understand what you mean with setting/unsetting. Where you call the add_filter() is up to you, the theme author. :)
    – fuxia
    Commented Dec 23, 2012 at 11:12
  • My understanding of the question was that the OP can edit theme files and therefor can create a wrapper function around comments_popup_link() and use it instead. AFAICT comments_popup_link() requires $post to be set to function. Commented Dec 23, 2012 at 11:38
  • 1
    Ah, I see. Made an update. :)
    – fuxia
    Commented Dec 23, 2012 at 11:47
  • 1
    wow. you guys are very proficient in wordpress.
    – Androliyah
    Commented Dec 23, 2012 at 19:27

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.