Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(); ?>
share|improve this question
add comment

1 Answer

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();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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