2

Hello guys I'm new to Wordpress and I'm having some issues. I'm making a custom theme and I need one of my pages to be password protected. I've read Wordpress codex on the subject and all the threads I found here but none of them helped me. I've made custom template that I use for my page.

My custom template is mostly hard coded and doesn't have the_content. This is my custom template https://jsbin.com/qayeso/edit?html

When I add password to a page using this template nothing happens. After reading stuff online I had the following idea.
I made another template and wanted to call my old template into it for password. This is the code:

<?php /* Template Name: PwProtect */ ?>

<?php
    global $post;

    if ( ! post_password_required( $post ) ) {
          // Your custom code should here
        echo get_testPage();

    }else{
        // we will show password form here
        echo get_the_password_form();
    }

?>

But when I try this I get the following error:

Fatal error: Call to undefined function get_testPage() in C:\wamp\www\fresenius\wp-content\themes\fresenius\indiPartnership.php on line 8

Is there a way to make this work ? Can I make my whole custom template password protected.

4

Okay so I made it work with include this is my updated code:

<?php /* Template Name: pw-protect */ ?>

<?php
    global $post;
    get_header();

    if ( ! post_password_required( $post ) ) {
          // Your custom code should here
        include('indiPartnership.php');


    }else{
        // we will show password form here
        echo get_the_password_form();
    }

?>
1

it's very easy to password protected to any page and post in WordPress.

first go on admin panel , click on all pages and quick edit any page you want to password protected and enter image description here

  • I actually try that it doesn't work for me. – Karadjordje May 17 '17 at 13:02
0

Use get_template_part instead of get_testPage();

<?php get_template_part( 'loop', 'index' ); ?>

File name should be like this loop-index.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.