16

How to Customize Excerpts for Password Protected WordPress Pages

Powered by WPCodeBox

Optimize your WordPress site! This snippet customizes excerpts for password-protected pages, allowing you to control content visibility and even integrate calls to action like “join now” with your favorite e-commerce plugin.


<?php

/** 
 * Snippet Name: Custom excerpt for password protected pages 
 * Snippet URL: https://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' );

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.