Whoops! Hiding password protected posts.

Edit – I no longer use Robo Gallery. I’m pretty sure it doesn’t play nicely with the most recent WordPress.

I love WordPress but sometimes it truly hurts me when the thing you love does something to some completely nonsensical. Seriously, if you can’t display the content, why even advertise that it’s there?

I use the Robo Gallery plugin to manage the display of photo galleries that I have. In this case I wanted to share family photos with family and friends. For whatever reason WordPress displays password protected posts keeping the title and preceding it with “PROTECTED”. Granted, you can’t see the contents of the post, but you can see a password login screen and it completely detracts from the ascetics of the website for everyone else. I found this site that had the snippet I needed to fix the problem.

To fix this you have to go into the functions.php of your theme and add the following:


function wpb_password_post_filter( $where = '' ) {
    if (!is_single() && !is_admin()) {
        $where .= " AND post_password = ''";
    return $where;
add_filter( 'posts_where', 'wpb_password_post_filter' );

And it all works like it should!

Tagged , ,