Let’s say you’ve successfully hidden your premium content with a password, either using WordPress’s built-in function or a password protection plugin. Unfortunately, you realize that the titles and excerpts of these posts still show up on many pages of your site – archive pages, category pages, and more.
So what should you do to completely remove them from public view? This article shows you exactly how to hide password-protected posts in WordPress.
Hide password-protected content from the WordPress loop with code
To hide password-protected posts from the WordPress loop, we use the pre_get_posts action, which allows us to modify the query by adding and removing conditions. This lets us tell WordPress to exclude password-protected posts.
Simply add the following code to your theme’s functions.php file:
add_action( 'pre_get_posts', 'prefix_exclude_password_protected_posts' );
function prefix_exclude_password_protected_posts( $query ) {
if ( ! $query->is_singular() && ! is_admin() ) {
$query->set( 'has_password', false );
}
}
Now your password-protected posts no longer appear on the homepage, in archives, or in widgets like “Latest posts.”

However, you can still visit the post by accessing it directly via URL.
If you want to make the posts visible to those who can edit them, use this code snippet instead:
function wpb_password_post_filter( $where = '' ) {
if (!is_single() && !current_user_can('edit_private_posts') && !is_admin()) {
$where .= " AND post_password = ''";
}
return $where;
}
add_filter( 'posts_where', 'wpb_password_post_filter' );
You’re finished. But what if you don’t want to touch a single line of code?
Hide password-protected WordPress content with the PPWP plugin
Adding code to your theme’s functions.php file may sound complicated if you’re not technically inclined. The PPWP plugin makes everything much easier.
This password protection plugin offers various features even in the free version, including:
- Protect unlimited pages and posts with multiple passwords
- Control the visibility of protected content
To hide password-protected posts from certain views on your website, follow this step-by-step guide.
Step 1 – Install and activate the PPWP plugin
There’s a free version of PPWP in the WordPress plugin directory that you can install on your site. In your admin dashboard, go to Plugins > Add New. Enter “password protection for WordPress” or “PPWP” in the search field.

Click Install Now and then Activate.
Step 2 – Protect your content with the PPWP plugin
While WordPress’s built-in function only allows you to protect a post with a single password, PPWP allows you to set an unlimited number of passwords.
Open the page or post you want to protect. In the top right corner of the edit page, you’ll see the Password Protection for WordPress section.

Enter as many passwords as you want here and click Submit to protect your content.
Step 3 – Hide protected content for certain views
Instead of using code like the method above, the PPWP plugin provides an easy-to-use interface that allows you to hide protected posts or pages directly in your admin dashboard.
Simply go to Password Protection for WordPress > Settings > General.
Here you’ll see the section Control content visibility. Select whether you want to hide the protected content from all pages.

Don’t forget to click Save Changes so that all your settings are saved. All your password-protected content will no longer display on the selected pages.
Conclusion
Displaying protected content in the WordPress frontend isn’t a good decision. It creates curiosity among those who don’t have passwords. In the worst case, they can guess the passwords to access your protected content.
To avoid this situation, you need to completely hide your protected content from the public. This article showed you 2 methods to achieve this. If you’re technically inclined, you can add some custom code to your theme functions.
If you’re not familiar with coding, the PPWP plugin is worth considering. With this plugin, you can not only easily password protect your content, but also control the visibility of protected posts via a user-friendly interface.
Install the PPWP plugin and remove your password-protected content from WordPress archive pages and category pages with ease.