Menü schliessen
Created: December 9th 2020
Last updated: December 9th 2020
Categories: IT Development,  Wordpress
Author: Marcus Fleuti

Wordpress: Create password-protected page

Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

Problem

You can set a page to password-protected if you are using a default wordpress theme. These themes are using the "the_content()" function, which is needed for a page to make it password protected. Our themes are not using "the_content()" function. That's why password-protected is not working on our themes.

Solution

To enable password-protected pages on our themes, we have to add some code to our template.php. You have to check for the password_required property in the way down below:

global $post;

get_header();
   if(post_password_required($post)):
     echo "this is password protected";
     echo get_the_password_form();
   endif;