nabinbajracharya.com.np

S.E.O, social marketing and affiliation

how to show excerpt for password protected post

Here is a code that will display of password protected post/page of wordpress. Use this in function.php

Here is a code that will display of password protected post/page of wordpress. Use this in function.php

<?php

function display_protected_excerpts($excerpt)
{
global $post;
if (!empty($post->post_password)) {
$output = $post->post_excerpt;
$output = apply_filters(‘get_the_excerpt’, $output);
return $output;
}
return $excerpt;
}
add_filter(‘the_excerpt’,’display_protected_excerpts’, 0);

function display_excerpt_on_protected_posts($content)
{
global $post;
$replacement_text = $post->post_excerpt;
$replacement_text = apply_filters(‘get_the_excerpt’, $replacement_text);
return str_replace(‘This post is password protected. To view it please enter your password below:’,$replacement_text, $content);
}
add_filter(‘the_content’,’display_excerpt_on_protected_posts’, 10);

?>

Advertisement