allow readers to see the excerpt

Members 5 posts 2 voices

  1. Assuming that you’re manually writing the excerpt in the “Excerpt” box, you can certainly do that. The following code will handle it.

    add_action( 'after_setup_theme', 'th_disable_members_excerpt' );
    
    function th_disable_members_excerpt() {
    
    	remove_filter( 'get_the_excerpt',  'members_content_permissions_protect', 95 );
    	remove_filter( 'the_excerpt',      'members_content_permissions_protect', 95 );
    }

    Auto-generated excerpts are a different story though. Because they’re auto-generated from the post content, WordPress will call the the_content filter hook, which is what is used to block the full content.

  2. Thanks, Justin. These would be auto-generated. I tried changing the code you posted to get_the_content and the_content and that didn’t work. I planned on wrapping the code in an !is_singular() check so that this only runs on archive templates. Any suggestions?

  3. You might be able to do something like this:

    add_action( 'template_redirect', 'th_disable_members_excerpt' );
    
    function th_disable_members_excerpt() {
    
    	if ( is_singular() )
    		return;
    	
    	remove_filter( 'the_content',      'members_content_permissions_protect', 95 );
    	remove_filter( 'get_the_excerpt',  'members_content_permissions_protect', 95 );
    	remove_filter( 'the_excerpt',      'members_content_permissions_protect', 95 );
    }