How to Password Protect WordPress Custom Post Type

When creating custom post types for portfolios or e-commerce products, you might intend to make them invisible to a selected group of people. You offer premium products that only specific members are allowed to view or make purchases.

There are various ways to protect custom content such as restricting access to user roles with a membership plugin and adding code to your theme files.

Although a membership plugin is awesome in many cases, you might be overwhelmed when protecting a single custom post type. That’s where password protection comes into handy to lock your custom post type. There is no subscription or registration needed.

In this article, we will define custom post types, why you want to secure them, and 2 ways to password protect WordPress custom post type.

What Are WordPress Custom Post Types?

Custom post types refer to any post type that is not included in WordPress default post types: Post, Page, Attachment, Revision, and Navigation Menu. While the content of these default post types follows the same layout, custom post types allow you to create streamlined and efficient content.

You can use custom post type to generate specific kinds of content that will better suit your company’s demand: product descriptions, testimonials, portfolios, and so on. They’re relatively easy for you as well as your team members to create and manage.

Why Do You Need to Password Protect Custom Post Types?

These are common cases when you want to password protect WordPress custom post type:

#1 Build product pages for E-commerce sites

You own an e-commerce site and intend to sell customer-specific products. For example, a manufacturer of shoes might want to restrict access to the public view except for the wholesalers.

Since you create product pages from custom post types, it’s important to password protect these custom posts so that standard users can’t view your premium products or make purchases.

#2 Make online portfolios with WordPress custom post type

Online portfolios store the work samples that you’ve done. They’re a great way to impress your employers and start on your careers. You can use custom post types to create a cool and personalized portfolio.

In fact, portfolios belong to personal properties so they shouldn’t be visible to the public and those you can’t trust in particular. Locking portfolios with a password prevents unauthorized people from snooping around your work.

#3 Use WordPress custom post type to create image galleries

Designing image galleries with custom post types makes it easy for you to manage images. You sometimes want to show your image galleries to a specific group of users or an individual. Simply add a password to your image gallery so only those with the correct password can view your photos.

Let’s take photographers as an example. Setting a password to protect galleries helps hide their photos from everyone except particular clients.

#4 Offer coupon custom post type

You intend to offer discounts for your customers through posts. The coupon post’s style will look different from content-focused standard blog posts. It will mainly include a short introduction of your product and a coupon code for customers to click on and get the discount. That’s why you need a custom post to generate this kind of content.

You can cover these coupons under a password form so that only premium customers with the correct password are able to get the discount.

Password Protect Custom Post Type Manually

You can add some code to your theme files if you’re familiar with programming. Follow these 3 simple steps to manually password protect your WordPress custom post type:

  1. Head to AppearanceTheme Editor in your WordPress dashboard
  2. Go to Theme Functions (functions.php) files under the Theme Files navigation menu
  3. Place this code to the top of your functions.php file:
<?php

  //Password Protect programmatically

 function passwordProtectPosts($post_object) {

//Checks if current post is a specific custom post type

if ($post_object->post_type!='tutorial')) {

return;

}

//Checks if current post is from a specific category

/*if (!in_category(array('protected'))) {

return;

}*/

$post_object->post_password = 'your_password';

}

add_action('the_post', 'passwordProtectPosts');

?>

In fact, this programming method is not an effective solution for all WordPress site owners. In case you’re not a coding wiz, you should install a third-party plugin to remove the code copy-paste and simplifies the password protection process.

Use Password Protect WordPress Pro Plugin

Password Protect WordPress Pro offers a great solution to secure your custom post type with a password, and product pages in particular.

Take these 2 main steps to lock your custom post type with Password Protect WordPress Pro plugin

Install Password Protect WordPress Pro

The following guide shows you how to install Password Protect WordPress Pro

  1. Download Password Protect WordPress Pro plugin
  2. Head to PluginAdd New in your WordPress dashboard
  3. Click Upload PluginChoose File
  4. Choose the Password Protect WordPress zip file you’ve downloaded to the local machine and hit Enter
  5. Activate the plugin

ppwp-upload-plugin

Start password protecting product pages with PPWP Pro

Upon activation, the plugin will be added right to your WordPress navigation menu. You can click the icon and make some settings to secure your custom post type with a password. These 5 steps guide you on how to simply password protect product pages with the plugin:

  1. Click on Password Protect WordPress icon in your WordPress navigation menu
  2. Choose Products in the Post Type Protection section
  3. Save your changes
  4. Head to your Products and assign passwords to your desired pages

ppwp-password-protect-custom-post-type

There are many setting options that you should take a look at to maximize the plugin password protection features.

Password Protect WordPress Pro allows you to set cookie expiration time so that users can reaccess the protected content without entering the password again.

In addition, it’s available for you to choose which roles can freely access the protected product pages without filling the password form. Admin doesn’t have to enter passwords by default. Besides the admin role, you can select other whitelist roles including post authors, log-in users. You can also pick multiple user roles at the same time.

Enabling the Password Protect Child Pages feature means that all the sub-pages will be automatically assigned a password when the parent product page is protected. It saves your time of setting passwords for individual pages, compared to WordPress built-in password protection feature.

Once protected, your custom post types won’t be indexed and shown up in Google or any other search engine results by default.

Ready to Lock Your Custom Post Types?

When using WordPress custom post types for creating portfolios or product pages, you ought to think of who can access your content. There are various ways to secure your custom post type and password protection proves the simplest solution.

Install Password Protect WordPress Pro to hide your WordPress custom post type today!

Leave a Reply

Your email address will not be published. Required fields are marked *