When managing your website, you might have wanted to hide password protected posts from the WordPress loop. The good news is that it’s surprisingly easy to do.
A common issue site owners face is that password protected posts still show up on the homepage or archive pages with the “Protected” prefix.
This can confuse visitors and break the visual flow of your site. It also raises privacy concerns since the post title is still publicly visible.
In this guide, you will learn what exactly the WordPress loop is, why it’s important to hide password protected posts from it, how to actually do it, and a bonus way to protect content in Elementor using The Plus Addons.
Why Hide Password Protected Posts from WordPress Loop?
You might be familiar with how WordPress deals with password protected posts. When you publish a password-protected post, the title still shows up on your website, with a “Private” or “Protected” label.

Visitors to your website cannot see this content without a password or approval from site admins. However, in effect, your privacy is not preserved.
There are additional problems that accompany this faulty feature.
For one, website visitors cannot see the content, but the title is still visible to them. A brute-force attack can also leave you and your private data vulnerable.
By excluding password protected posts from the WordPress loop, you improve the user experience and keep your private posts truly private.
So, it becomes absolutely vital to exclude password protected posts from the WordPress loop. Let’s dive a little deeper into the technicalities in the next section.
What is the WordPress Loop and Password Protection?
Simply put, the WordPress loop is a PHP(hypertext preprocessor) code snippet that displays posts on your blog.
WordPress itself defines the loop as the “main process” of WordPress. It runs on your homepage, category pages, and search results.
It works by retrieving relevant post data from a database, and is responsible for the posts visible for any website visitors.
Password protection on WordPress is a feature that lets you protect individual posts or pages by assigning a password. Only users who enter that password can view the content.
However, by default, these posts still appear in loops, archive pages, and even RSS feeds, with a “This content is password protected” message, or with a “Protected” prefix before the title.
So if the posts are still protected by a password, why does it pose a problem? Let’s discuss why.
The Problem with Visible Password Protected Posts
One major problem WordPress site owners face is that password protected posts can still appear publicly. Even without access to the content, the title might give away sensitive information and the contents of the page.
This can prompt users to guess the password or try brute-force methods to access the post. As a result, your website risks exposing private information and inviting unwanted access attempts.
If you feel the default password-protected pages in WordPress look simple, here’s how to customize password-protected pages in WordPress.
How to Hide Password Protected Posts from WordPress Loop (Working Methods)
If you’re looking to hide password protected posts from the WordPress loop, there are a couple of simple and effective ways to do it.
Let’s explore two working methods to achieve this.
Method 1: Using a Code Snippets Plugin
Although it seems code heavy at first, this is the easiest and safest way to hide password protected posts, without touching your theme files.
Nexter Extension is the most popular option amongst WordPress website owners.
Step 1: Install the Code Snippets Plugin
From your WordPress dashboard, navigate to Plugins > Add Plugin.

In the search bar visible to the right-side of your screen, search for “Nexter Extension” and press enter. The Nexter Extension Plugin should be the first plugin visible on your screen.

Click the plugin link and install it.

Once the plugin is installed, activate it. Now you can use it for hiding password-protected content from the WordPress loop.
Step 2: Hide the Posts
In the left-hand column on your WordPress dashboard, you will see a new options for “Nexter Extension”.
Navigate to Nexter Extension > Code Snippets.

Add a New Snippet by clicking on “Create New”.

On this screen, add a name for your snippet like: “Hide Protected Posts from Loop”. This will make it easy to reference in the future.
In the code preview, paste the following code:
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' );
Your screen should look something like this:

Step 3: Save and Activate the Snippet
Now, to the top right of your screen, toggle the switch to activate the snippet, and save it.

That’s it! Your protected posts will no longer appear on the homepage, archives, or search results. And if you want to reverse the change, you can simply deactivate the snippet.
Plugins are an easy method to hide password protected posts from WordPress. There is another method that gives more customization and control, which we will look at in the next section.
Running into invalid template errors when designing your website? Read this article on how to fix Elementor ‘Invalid template type’ error.
Method 2: Using Custom Functions.php [for Advanced Users, Not Recommended for Beginners]
If you’re comfortable editing theme files, this method works too. But it is not recommended for beginners, especially if you’re using a theme that receives regular updates.
It is best to back up your website before you try this method.
Step 1: Navigate to Theme File Editor
From your WordPress dashboard, navigate to Appearance > Theme File Editor.

Open your functions.php file from the Theme Files column to the right of your screen.

Step 2: Protect your Posts
To this file, add the same code snippet provided in Method 1.

Once added, click on “Update File” at the bottom of the web page to save and apply your changes.
Remember to take a full backup before editing core theme files, as it can protect you from the site breaking down.
Recommended Read: 5 Best WordPress Backup Plugins [Backup & Restore]
How to Allow Role-Based Access to Password Protected Posts?
If you follow one of the methods listed above, password-protected posts will be hidden from all users.
Let’s say you still want to show protected posts to certain user roles (like admins or logged-in subscribers).
You can achieve this using a simple conditional tag.
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' );
This will provide post access to users with administrator and editor roles only.
BONUS: How to Use Elementor for Content Protection?
Using custom functions provides flexibility, but there are more convenient, no-code options available for content protection For instance, the Protected Content Widget from The Plus Addons for Elementor.
It lets you protect your content using AJAX based security, based on user roles, as mentioned above, without needing to write a single line of code.
Along with these security features, the widget lets you create customized layouts for an elevated website design, and through it, a superior user experience.
First, install and activate The Plus Addons for Elementor and activate the Protected Content Widget from Dashboard > The Plus Addons > Widgets.
Then, follow the steps below:
- Add the Protected Content widget to your WordPress page.
- Set the appropriate protected content in the Protected Content tab.
- Then go to the Protection Type tab and select User Role from the Protection Type dropdown.
- After that from the Select Roles section you have to add the user type. You can select multiple user types.
Wrapping Up
Hiding password protected posts from the WordPress loop is a small change that can have a big impact on your site’s security, performance, and user experience.
Whether you choose to use a plugin or a bit of code, you now have everything you need to exclude password protected posts from the WordPress loop.
The Protected Content Widget by the Plus Addons for Elementor makes it effortless to protect and personalize content, without writing a single line of code.
The plugin’s utility does not stop there. With The Plus Addons for Elementor, you get access to 120+ powerful and fully customizable widgets that enhance your Elementor editor and take your website to the next level.
Enhancing the functionality of your Elementor editor and creating wholesome WordPress websites has never been easier.
FAQs on Hiding Password Protected Posts from WordPress Loop
Will hiding password protected posts affect my SEO?
Yes, hiding password protected posts can affect your website SEO. When you hide password protected posts from the WordPress loop or search results, search engines won’t index them. This means any valuable content within those posts won’t contribute to your site’s SEO.
Can I still access my hidden password protected posts?
Even if password protected posts are hidden from public listings or the main WordPress loop, they’re still accessible via their direct URL. You’ll just need the correct password or be logged in with appropriate permissions. Admins can always view them from the WordPress dashboard as well.
Do I need to use a plugin or can I hide password protected posts with code?
You don’t necessarily need a plugin. With a few lines of custom code in your theme’s functions.php file you can hide password protected posts, but using a plugin like Nexter Extension can simplify the process if you’re a beginner.
Is hiding password protected posts compatible with all WordPress themes?
Hiding password protected posts using standard WordPress filters works with the majority of themes. However, some themes with custom queries or post loops might not fit well with these filters. Testing and making minor adjustments can help avoid performance issues..
How can I show password protected posts only to registered users?
For restricting content to certain users only, you can use a content restriction plugin like the Protected Content Widget from The Plus Addons. The alternate option is to implement custom code that checks if a user is logged in before displaying password protected content.