WordPress Snippets at WPcustoms

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: http://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' );