Outline
Original Posts
〈Display Excerpt Of Password Protected Posts For WordPress〉
As a default, posts with password protected cannot display excerpts. However, it is helpful to hack it to achieve marketing goals. For example, you can write some information to require users to subscribe to the newsletter, then send them the password with e-mail.
Not Using Built-In Function
There are two built-in functions in WordPress to display excerpt, the_excerpt() and get_the_excerpt(). However, both of them will hide excerpt for posts with passwords. There are alternatives as below, and you can add it to the archive page or single page.
$post = get_post();
echo $post->post_excerpt
Extend WooCommerce Templates
As the default WooCommerce template content-single-product.php, there is a piece of code to handle with passwords.
if ( post_password_required() ) {
echo get_the_password_form(); // WPCS: XSS ok.
return;
}
And we can extend it like this:
if ( post_password_required() ) { ?>
echo get_the_password_form(); // WPCS: XSS ok.
echo "<p>".$post->post_excerpt."</p>";
return;
}
By the way, if the post isn’t locked down or the password was validated, post_password_required() will return false for both scenarios.
Related Posts
〈Learn Python And R On DataCamp. Start Your Data Science Career.〉
Τhat is a very good tip especially to those fresh
to the blogospһere. Brief but very accurate informatіon… Many tһanks for sharing this one.
A must гead post!
2020-12-02
12:32:42
Keep this going pleasе, great job!
2020-12-01
17:37:51