Custom excerpt for password protected pages

WordPress shows the excerpt for password protected pages. This function changes the excerpt output for protected pages. Easy to modify and extend with your favorite ecommerce plugin to show a “join now” button.

/**
 * Snippet Name: Custom excerpt for password protected pages
 * Snippet URL: https://www.wpcustoms.net/snippets/custom-excerpt-password-protected-pages/
 */
  function password_required_excerpt( $excerpt ) {
    if ( post_password_required() )
    {
        $excerpt = 'This is a private page to request the password please contact the site administrator.';
    }

    return $excerpt;
}
add_filter( 'the_excerpt', 'password_required_excerpt' ); 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x