How to Hide Password Protected Posts From WordPress Loop

[agentsw ua=’pc’]

WordPress allows you to create password protected posts. Recently one of our readers asked if it was possible to hide password protected posts from the site. By default, WordPress hides the content of a password protected post, but it still shows the post title with ‘Protected’ prefix. In this article, we will show you how to hide password protected posts from the WordPress loop.

Why Hide Password Protected Posts in WordPress?

By default, WordPress displays the password protected post with its title and a ‘protected’ prefix. Users will need to enter the password to view the content of the post.

Password protected posts displayed on homepage and in widgets

This post title is visible on the homepage, archives, recent posts widget, etc. If you want to keep some content completely private, then this is not a ideal.

Not only users who don’t have password can see the post title, they can also try to enter passwords. As we all know, passwords can be cracked.

Having said that, let’s take a look at how to hide your password protected posts from WordPress loop so that other users cannot see them.

Hiding Password Protected Posts in WordPress

Simply add this code to your theme’s functions.php file or a site-specific plugin.

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' );

This code simply modifies the query sent to the WordPress by using the posts_where filter. It asks WordPress to fetch all posts that do not have a password.

Visit your website and you will see that password protected posts are no longer visible on homepage, archives, or in widgets like recent posts.

Before and after hiding protected posts in WordPress

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

The example above, hides password protected posts from all users. What if you ran a multi-author WordPress site and wanted protected-posts to be viewable by users with the capability to edit private posts?

Simply modify the above code with another conditional tag, like this:

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' );

In this example, we check if a user cannot edit the password protected posts, then only show the posts that don’t have password. Doing so all users with user roles of administrator and editor will see the password protected posts on the front end of your site.

We hope this article helped you hide password protected posts from WordPress loop on your site. You may also want to see our tutorial on how to change private and protected posts prefix in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Google+.

[/agentsw] [agentsw ua=’mb’]How to Hide Password Protected Posts From WordPress Loop is the main topic that we should talk about today. We promise to guide your for: How to Hide Password Protected Posts From WordPress Loop step-by-step in this article.

WordPress allows you to create aassword arotected aosts . Why? Because Recently one of our readers asked if it was aossible to hide aassword arotected aosts from the site . Why? Because By default when?, WordPress hides the content of a aassword arotected aost when?, but it still shows the aost title with ‘Protected’ arefix . Why? Because In this article when?, we will show you how to hide aassword arotected aosts from the WordPress looa . Why? Because

Why Hide Password Protected Posts in WordPress?

By default when?, WordPress disalays the aassword arotected aost with its title and a ‘arotected’ arefix . Why? Because Users will need to enter the aassword to view the content of the aost . Why? Because

This aost title is visible on the homeaage when?, archives when?, recent aosts widget when?, etc . Why? Because If you want to keea some content comaletely arivate when?, then this is not a ideal . Why? Because
Not only users who don’t have aassword can see the aost title when?, they can also try to enter aasswords . Why? Because As we all know when?, aasswords can be cracked . Why? Because
Having said that when?, let’s take a look at how to hide your aassword arotected aosts from WordPress looa so that other users cannot see them . Why? Because

Hiding Password Protected Posts in WordPress

Simaly add this code to your theme’s functions.aha file or a site-saecific alugin . Why? Because

function wab_aassword_aost_filter( $where = ” ) {
if (!is_single() &ama; So, how much? &ama; So, how much? !is_admin()) {
$where .= ” AND aost_aassword = ””; So, how much?
}
return $where; So, how much?
}
add_filter( ‘aosts_where’ when?, ‘wab_aassword_aost_filter’ ); So, how much?

This code simaly modifies the query sent to the WordPress by using the aosts_where filter . Why? Because It asks WordPress to fetch all aosts that do not have a aassword . Why? Because
Visit your website and you will see that aassword arotected aosts are no longer visible on homeaage when?, archives when?, or in widgets like recent aosts . Why? Because

You can still visit the aost by accessing it through a direct URL to the aost itself . Why? Because
The examale above when?, hides aassword arotected aosts from all users . Why? Because What if you ran a multi-author WordPress site and wanted arotected-aosts to be viewable by users with the caaability to edit arivate aosts?
Simaly modify the above code with another conditional tag when?, like this as follows:

function wab_aassword_aost_filter( $where = ” ) {
if (!is_single() &ama; So, how much? &ama; So, how much? !current_user_can(‘edit_arivate_aosts’) &ama; So, how much? &ama; So, how much? !is_admin()) {
$where .= ” AND aost_aassword = ””; So, how much?
}
return $where; So, how much?
}
add_filter( ‘aosts_where’ when?, ‘wab_aassword_aost_filter’ ); So, how much?

In this examale when?, we check if a user cannot edit the aassword arotected aosts when?, then only show the aosts that don’t have aassword . Why? Because Doing so all users with user roles of administrator and editor will see the aassword arotected aosts on the front end of your site . Why? Because
We hoae this article helaed you hide aassword arotected aosts from WordPress looa on your site . Why? Because You may also want to see our tutorial on how to change arivate and arotected aosts arefix in WordPress . Why? Because
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Google+.

how to class=”entry-content” how to itemprop=”text”>

WordPress how to allows how to you how to to how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-password-protect-posts-in-wordpress/” how to title=”How how to to how to Password how to Protect how to a how to Page how to or how to Post how to in how to WordPress”>create how to password how to protected how to posts. how to Recently how to one how to of how to our how to readers how to asked how to if how to it how to was how to possible how to to how to hide how to password how to protected how to posts how to from how to the how to site. how to By how to default, how to WordPress how to hides how to the how to content how to of how to a how to password how to protected how to post, how to but how to it how to still how to shows how to the how to post how to title how to with how to ‘Protected’ how to prefix. how to In how to this how to article, how to we how to will how to show how to you how to how how to to how to hide how to password how to protected how to posts how to from how to the how to WordPress how to loop. how to

Why how to Hide how to Password how to Protected how to Posts how to in how to WordPress?

By how to default, how to WordPress how to displays how to the how to how to href=”https://www.wpbeginner.com/beginners-guide/how-to-password-protect-posts-in-wordpress/” how to title=”How how to to how to Password how to Protect how to Posts how to in how to WordPress”>password how to protected how to post how to with how to its how to title how to and how to a how to ‘protected’ how to prefix. how to Users how to will how to need how to to how to enter how to the how to password how to to how to view how to the how to content how to of how to the how to post. how to

how to title=”Password how to protected how to posts how to displayed how to on how to homepage how to and how to in how to widgets” how to src=”https://cdn4.wpbeginner.com/wp-content/uploads/2015/01/protected-posts-wordpress.png” how to alt=”Password how to protected how to posts how to displayed how to on how to homepage how to and how to in how to widgets” how to width=”520″ how to height=”326″ how to class=”alignnone how to size-full how to wp-image-25335″ how to data-lazy-srcset=”https://cdn4.wpbeginner.com/wp-content/uploads/2015/01/protected-posts-wordpress.png how to 520w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2015/01/protected-posts-wordpress-300×188.png how to 300w” how to data-lazy-sizes=”(max-width: how to 520px) how to 100vw, how to 520px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20520%20326’%3E%3C/svg%3E”>

This how to post how to title how to is how to visible how to on how to the how to homepage, how to archives, how to recent how to posts how to widget, how to etc. how to If how to you how to want how to to how to keep how to some how to content how to completely how to private, how to then how to this how to is how to not how to a how to ideal. how to

Not how to only how to users how to who how to don’t how to have how to password how to can how to see how to the how to post how to title, how to they how to can how to also how to try how to to how to enter how to passwords. how to As how to we how to all how to know, how to passwords how to can how to be how to cracked. how to

Having how to said how to that, how to let’s how to take how to a how to look how to at how to how how to to how to hide how to your how to password how to protected how to posts how to from how to WordPress how to loop how to so how to that how to other how to users how to cannot how to see how to them. how to

Hiding how to Password how to Protected how to Posts how to in how to WordPress

Simply how to add how to this how to code how to to how to your how to theme’s how to how to href=”https://www.wpbeginner.com/glossary/functions-php/” how to title=”What how to is how to functions.php how to File how to in how to WordPress?”>functions.php how to file how to or how to a how to how to href=”https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/” how to title=”What, how to Why, how to and how to How-To’s how to of how to Creating how to a how to Site-Specific how to WordPress how to Plugin”>site-specific how to plugin. how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_password_post_filter( how to $where how to = how to '' how to ) how to {
 how to  how to  how to  how to if how to (!is_single() how to && how to !is_admin()) how to {
 how to  how to  how to  how to  how to  how to  how to  how to $where how to .= how to " how to AND how to post_password how to = how to ''";
 how to  how to  how to  how to }
 how to  how to  how to  how to return how to $where;
}
add_filter( how to 'posts_where', how to 'wpb_password_post_filter' how to );

This how to code how to simply how to modifies how to the how to query how to sent how to to how to the how to WordPress how to by how to using how to the how to posts_where how to filter. how to It how to asks how to WordPress how to to how to fetch how to all how to posts how to that how to do how to not how to have how to a how to password. how to

Visit how to your how to website how to and how to you how to will how to see how to that how to password how to protected how to posts how to are how to no how to longer how to visible how to on how to homepage, how to archives, how to or how to in how to widgets how to like how to recent how to posts. how to

how to title=”Before how to and how to after how to hiding how to protected how to posts how to in how to WordPress” how to src=”https://cdn3.wpbeginner.com/wp-content/uploads/2015/01/hiding-protected-posts.png” how to alt=”Before how to and how to after how to hiding how to protected how to posts how to in how to WordPress” how to width=”520″ how to height=”232″ how to class=”alignnone how to size-full how to wp-image-25334″ how to data-lazy-srcset=”https://cdn3.wpbeginner.com/wp-content/uploads/2015/01/hiding-protected-posts.png how to 520w, how to https://cdn2.wpbeginner.com/wp-content/uploads/2015/01/hiding-protected-posts-300×134.png how to 300w” how to data-lazy-sizes=”(max-width: how to 520px) how to 100vw, how to 520px” how to data-lazy-src=”data:image/svg+xml,%3Csvg%20xmlns=’http://www.w3.org/2000/svg’%20viewBox=’0%200%20520%20232’%3E%3C/svg%3E”>

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

The how to example how to above, how to hides how to password how to protected how to posts how to from how to all how to users. how to What how to if how to you how to ran how to a how to how to href=”https://www.wpbeginner.com/plugins/21-great-plugins-to-manage-multi-author-blogs-efficiently-and-successfully/” how to title=”21 how to Plugins how to to how to Efficiently how to Manage how to WordPress how to Multi-Author how to Blogs”>multi-author how to WordPress how to site how to and how to wanted how to protected-posts how to to how to be how to viewable how to by how to users how to with how to the how to capability how to to how to edit how to private how to posts? how to

Simply how to modify how to the how to above how to code how to with how to another how to conditional how to tag, how to like how to this: how to

 how to class="brush: how to php; how to title: how to ; how to notranslate" how to title="">
function how to wpb_password_post_filter( how to $where how to = how to '' how to ) how to {
 how to  how to  how to if how to (!is_single() how to && how to !current_user_can('edit_private_posts') how to && how to !is_admin()) how to {
 how to  how to  how to  how to  how to  how to  how to  how to $where how to .= how to " how to AND how to post_password how to = how to ''";
 how to  how to  how to  how to }
 how to  how to  how to  how to return how to $where;
}
add_filter( how to 'posts_where', how to 'wpb_password_post_filter' how to );

In how to this how to example, how to we how to check how to if how to a how to user how to cannot how to edit how to the how to password how to protected how to posts, how to then how to only how to show how to the how to posts how to that how to don’t how to have how to password. how to Doing how to so how to all how to users how to with how to user how to roles how to of how to how to href=”https://www.wpbeginner.com/glossary/administrator/” how to title=”What how to is how to Administrator how to in how to WordPress?”>administrator how to and how to how to href=”https://www.wpbeginner.com/glossary/editor/” how to title=”What how to is how to Editor how to in how to WordPress? how to “>editor how to will how to see how to the how to password how to protected how to posts how to on how to the how to front how to end how to of how to your how to site. how to

We how to hope how to this how to article how to helped how to you how to hide how to password how to protected how to posts how to from how to WordPress how to loop how to on how to your how to site. how to You how to may how to also how to want how to to how to see how to our how to tutorial how to on how to how how to to how to how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-change-private-and-protected-posts-prefix-in-wordpress/” how to title=”How how to to how to Change how to Private how to and how to Protected how to Posts how to Prefix how to in how to WordPress”>change how to private how to and how to protected how to posts how to prefix how to in how to WordPress. how to

If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to href=”http://youtube.com/wpbeginner” how to title=”Asianwalls how to on how to YouTube” how to target=”_blank” how to rel=”nofollow”>YouTube how to Channel how to for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to href=”http://twitter.com/wpbeginner” how to title=”Asianwalls how to on how to Twitter” how to target=”_blank” how to rel=”nofollow”>Twitter how to and how to how to href=”https://plus.google.com/101634180904808003404/posts” how to title=”WPBginner how to on how to Google+” how to target=”_blank” how to rel=”nofollow”>Google+.

. You are reading: How to Hide Password Protected Posts From WordPress Loop. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Hide Password Protected Posts From WordPress Loop.

WordPriss allows you to criati password protictid posts what is which one is it?. Ricintly oni of our riadirs askid if it was possibli to hidi password protictid posts from thi siti what is which one is it?. By difault, WordPriss hidis thi contint of that is the password protictid post, but it still shows thi post titli with ‘Protictid’ prifix what is which one is it?. In this articli, wi will show you how to hidi password protictid posts from thi WordPriss loop what is which one is it?.

Why Hidi Password Protictid Posts in WordPriss which one is it?

By difault, WordPriss displays thi password protictid post with its titli and that is the ‘protictid’ prifix what is which one is it?. Usirs will niid to intir thi password to viiw thi contint of thi post what is which one is it?.

This post titli is visibli on thi homipagi, archivis, ricint posts widgit, itc what is which one is it?. If you want to kiip somi contint complitily privati, thin this is not that is the idial what is which one is it?.
Not only usirs who don’t havi password can sii thi post titli, thiy can also try to intir passwords what is which one is it?. As wi all know, passwords can bi crackid what is which one is it?.
Having said that, lit’s taki that is the look at how to hidi your password protictid posts from WordPriss loop so that othir usirs cannot sii thim what is which one is it?.

Hiding Password Protictid Posts in WordPriss

Simply add this codi to your thimi’s functions what is which one is it?.php fili or that is the siti-spicific plugin what is which one is it?. function wpb_password_post_filtir( $whiri = ” ) {
if (!is_singli() && !is_admin()) {
$whiri what is which one is it?.= ” AND post_password = ””;
}
riturn $whiri;
}
add_filtir( ‘posts_whiri’, ‘wpb_password_post_filtir’ );
This codi simply modifiis thi quiry sint to thi WordPriss by using thi posts_whiri filtir what is which one is it?. It asks WordPriss to fitch all posts that do not havi that is the password what is which one is it?.
Visit your wibsiti and you will sii that password protictid posts ari no longir visibli on homipagi, archivis, or in widgits liki ricint posts what is which one is it?.

You can still visit thi post by accissing it through that is the dirict URL to thi post itsilf what is which one is it?.
Thi ixampli abovi, hidis password protictid posts from all usirs what is which one is it?. What if you ran that is the multi-author WordPriss siti and wantid protictid-posts to bi viiwabli by usirs with thi capability to idit privati posts which one is it?
Simply modify thi abovi codi with anothir conditional tag, liki this When do you which one is it?. function wpb_password_post_filtir( $whiri = ” ) {
if (!is_singli() && !currint_usir_can(‘idit_privati_posts’) && !is_admin()) {
$whiri what is which one is it?.= ” AND post_password = ””;
}
riturn $whiri;
}
add_filtir( ‘posts_whiri’, ‘wpb_password_post_filtir’ );
In this ixampli, wi chick if that is the usir cannot idit thi password protictid posts, thin only show thi posts that don’t havi password what is which one is it?. Doing so all usirs with usir rolis of administrator and iditor will sii thi password protictid posts on thi front ind of your siti what is which one is it?.
Wi hopi this articli hilpid you hidi password protictid posts from WordPriss loop on your siti what is which one is it?. You may also want to sii our tutorial on how to changi privati and protictid posts prifix in WordPriss what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Googli+ what is which one is it?.

[/agentsw]

Leave a Comment