ordPress allows you to create password protected posts . Recently, one of our readers asked if it is possible to hide password protected posts on the site. By default, WordPress hides the content of a password protected post but still displays the post title with the prefix “Protected”. 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 the prefix “protected”. Users must enter the password to see the post content.
This post title is visible on the homepage, archive, recent posts widget, etc. If you want to keep certain content completely secret, this is not ideal.
Not only users who don't have a password can see the list of saudi arabia cell phone number post title, they can also try to enter passwords. As we all know, passwords can be cracked.
So let’s see how to hide your password protected posts from the WordPress loop so that other users cannot see them.
Simply paste this code into your theme's functions.php file or into a site-specific plugin .
This code simply changes the query sent to WordPress 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 displayed on the homepage, in the archive, or in widgets such as “Recent Posts”.
Before and after hiding protected posts in WordPress
You can still visit the post by accessing the post itself via a direct URL.
In the example above, password protected posts are hidden from all users. What if you run a multi-author WordPress site and want protected posts to be viewable by users with the ability to edit private posts?
How to Hide Password Protected Posts from WordPress Loop
-
- Posts: 640
- Joined: Sat Dec 21, 2024 5:45 am