0

I recently switched to a new theme, and it does not seem to have the functionality to password-protect individual pages. It only displays "Protected" in page title, but still shows the content without prompting for password. How can I enable this manually? I tried to add (if ( post_password_required( $post ) ) { into a custom page template, but it didn't work. Please help me with correct code here or some other solution. Thanks a lot!

 <?php 
// Template Name: Password Protected 
get_header(); ?>



<!-- Margin -->
<div class="margin-2">

<div class="spacing-40"></div>

<!-- Single full Page Container-->
    <div id="single-full">

    <h1 class="entry-header"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h1>

    <div class="spacing-20"></div>

        <div class="entry wide-entry">





<?php 

                        $my_postid = get_page( $page_id );//This is page id or post id
                        $content_post = get_post($my_postid);
                        $content = $content_post->post_content;
                        $content = apply_filters('the_content', $content);
                        //$content = str_replace(']]>', ']]>', $content);
                        echo $content; 
                        ?>

        </div>

    </div>
<!-- Single full Page Container-->

<!-- Margin -->
<div id="widget-container">
    <?php
    if ( !function_exists('dynamic_sidebar')
        || !dynamic_sidebar(2) ) : 
    endif;

    ?>
</div>

<!-- Margin -->

<div class="clr"></div>
<div class="spacing-20"></div>
</div>



<div class="clr"></div>
<div class="spacing-40"></div>
</div>



<?php get_footer(); ?>
1

Replace all of this:

$my_postid = get_page( $page_id );//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
//$content = str_replace(']]>', ']]>', $content);
echo $content; 

...with this:

the_content();

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.