How to Hide Password Protected Posts From WordPress

Let’s say you’ve successfully hidden your premium content under a password form, either using WordPress built-in function or any password protection plugins. Unfortunately, you realize that the posts’ titles and excerpts still show up on many pages on your site, e.g. archive page, category page, etc.

So what should you do to completely exclude them from the public eye?

No worries, we’ve got your back. In this article, we’ll guide you on how to hide password-protected posts from WordPress.

Let’s get started!

Why Do You Need to Hide Protected Posts from WordPress?

By default, protected posts will be listed on many pages on your site, including archive pages, category pages, search results, etc.

PPWP Pro: Show protected posts on Recent Posts widget

It’s the expected behavior, which is controlled by WordPress Loop. To be more specific, WordPress Loop is the code that displays the blog posts on your WordPress theme. It’s considered the most important part of the WordPress theme, which is responsible for displaying blog posts on the current page based on the parameters.

While this behavior makes it more convenient for readers to navigate on your site, it isn’t ideal to display protected content titles this way.

It puts your content’s security at risk. Users who don’t have passwords can still see your private posts and try to guess passwords. You know, “A fair booty makes many thieves”.

So never put yourself in that unexpected situation. Let’s take a look at how to hide your password-protected posts from the WordPress Loop now!

Hide Password Protected Content from WordPress Loop using Codes

To hide password-protected posts from WordPress Loop, we’ll hook to pre_get_posts action, which allows us to modify the query by adding and removing conditions. We will use it to tell WordPress to exclude password-protected posts.

To do that, simply add this 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 are no longer visible on the homepage, archives, or in widgets like recent posts.

PPWP Pro: Hide password protected posts from WordPress' Recent Posts widget

You can still visit the post by accessing it through a direct URL to the post itself though.

In case you want to make the posts visible to those who can edit them, use the following 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 done.

So, what if you don’t want to touch a line of code?

Let’s move to our next session!

Hide WordPress Password Protected Content with PPWP Plugin

Adding codes to your theme functions.php file might sound complicated if you’re non-tech-savvy, now you just need to install the PPWP plugin and everything turns out to be a cakewalk.

This password protection plugin gives you a lot of features even in its free version, including but not limited to:

  • Protect unlimited pages and posts with multiple passwords
  • Control protected content visibility

To hide password protected posts from certain views on your website, simply follow our step-to-step guide here:

Step 1: Instal and Activate the PPWP plugin

PPWP Pro: Password Protect WordPress Plugin

There is a free version of PPWP available in the WordPress plugin directory for you to install on your site. In your admin dashboard, navigate to Plugins > Add New.

In the search box, type Password Protect WordPress or PPWP.

PPWP Pro: Install Password Protect WordPress Plugin

Click Install Now then Activate.

Step 2: Password Protect Your Content with PPWP Plugin

While WordPress’ built-in function only allows you to protect a post with a single password, PPWP lets you set unlimited ones.

Open the page or post you want to protect, in the top right-hand corner of the Edit page, you’ll see the Password Protect WordPress section.

PPWP Pro: Protect posts with unlimited passwords

Here, enter as many passwords as you’d like to and press Submit to protect your content.

Step 3: Hide Protected Content from Certain Views

Instead of using codes like the above method, the PPWP plugin provides you with an easy-to-use UI to hide protected posts or pages right in your admin dashboard.

To achieve that, simply go to Password Protect WordPress > Settings > General.

Here, you’ll see the Control Content Visibility section. Choose to hide your protected content from any pages you’d like.

PPWP Pro: Hide WordPress password protected posts from certain views

Don’t forget to press Save Changes for all your settings to be saved.

You’re done!

All your password-protected content no longer appears on the selected pages.

Hide Your WordPress Password-Protected Posts Now!

Showing protected content on your WordPress frontend isn’t a good call. It arouses curiosity in those who don’t have passwords. In the worst scenario, they can guess the passwords to access your protected content.

To avoid that situation, you need to completely hide your protected content from the public eye. In this article, we’ve shown you 2 methods to achieve that.

If you’re tech-savvy, you can go ahead and add some custom codes to your (child) theme function.

In case you’re not familiar with coding, PPWP plugin is worth your consideration. Not only does this plugin allow you to password-protect your content without hassle but it also gives you a user-friendly UI to control the protected post’s visibility.

Install PPWP plugin and have your password-protected content removed from WordPress archive pages and category pages with ease now!