How to Password Protect Partial Content under Custom Fields

The common way to protect custom fields is hiding them under the whole page password protection. But what if you just need to protect partial and not entire custom field content?

Password Protect WordPress (PPWP) Pro gives you the ability to protect not only all custom fields but also their partial content. This solution works well with both built-in WordPress custom fields function and the well-known Advanced Custom Fields plugin.

Requirements:

We assume that you’ve already had a basic knowledge of custom fields as well as how to add and display them on your website.

In this article, we’ll show you how to protect just a part of content in WordPress custom fields and custom template by simply using our PPWP shortcode.

Password Protect Custom Fields Partial Content

Step 1: Create a new custom field and add your data

Step 2: Use PPWP shortcode to wrap the section you want to protect

[ppwp id="" class="" passwords="password1 password2" whitelisted_roles="administrator, editor"]
Put your protected content here
[/ppwp]

Step 3: Copy our custom code snippet to your theme files in where you want to display custom fields data

<?php
// Change "field-name" to your custom field name
echo '<div class="ppwp-is-custom-field" ppwp-data-mt="field-name">';
foreach( get_post_meta( get_the_ID(), 'field-name' ) as $meta_data ) {

    echo do_shortcode( $meta_data );
}
echo '</div>';
?>

You can find your custom field name when editing ACF custom fields as image below:

If you’re using WordPress custom fields function, find its name under Name column.

Lasted updated on August 28, 2020