If you’re using WordPress to build your website, then taking adequate security measures is a must. In a few cases, you may feel the need to protect a particular page or post. Well, in WordPress, it’s very much possible. You can set passwords for such pages or posts and prevent unauthorized access, thus enhancing security. In this guide, learn how to password-protect a WordPress post or page.

Step-by-Step Process

Here are the steps you need to take to protect a page/post with password:
  • Log in to your WordPress dashboard with admin credentials
  • Click on the post or page for which you want to set a password
  • From the Publish menu on the right-hand side, locate and click on “Privacy
  • Click on Edit for “Visibility : Public” option
  • In the new window, change the radio button from Public to Password protected
  • Set a password of your choice (but make it strong)
  • Click on OK to confirm the changes made
Now head back to that post or page. When you try to visit it, WordPress should ask for the password. Now it’s password-protected.

You can also completely hide the post/page if you want. For that, you need to make some changes in the functions.php file.

So open the functions.php file of your current theme which you can find by following this:

Code:
/home/sitename/public_html/wp-content/themes/theme1/functions.php
Theme1 is the current theme you’re using.

Once you open the file, copy and paste the following code:

Code:
// Completely Hide protected posts
functionexclude_protected($where) {
global $wpdb;
return $where .= " AND {$wpdb->posts}.post_password = '' ";
}
// display protected posts
functionexclude_protected_action($query) {
if( !is_single() && !is_page() && !is_admin() ) {
add_filter( 'posts_where', 'exclude_protected' );
}
}
Save the changes and exit.
You’ll notice that the page no longer exist on the website. If you want to view it, you’d have to use the URL and then provide the password.

So that’s how you password-protect a WordPress page or post.
Author
kumkumsharma
Views
116
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top