Created
July 10, 2017 09:41
-
-
Save braddalton/f125b2e5dff82ea24e9ac7c086a298df to your computer and use it in GitHub Desktop.
Hide Posts From Logged Out Users https://wp.me/p1lTu0-gTu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php Do NOT copy this opening php tag | |
add_filter( 'the_content', 'filter_content', 10, 1 ); | |
function filter_content( $content ) { | |
$limit = wp_trim_words( get_the_content(), 20, '.....' ); | |
$login_form = sprintf( '<p><h4 class="restricted-post"><a href="%s">Login</a> to view the full content</h4></p>', wp_login_url( get_permalink() ) ); | |
$limit = $limit . $login_form; | |
$output = ! is_user_logged_in() && in_category( 'lifestyle' ) && is_singular( 'post' ) ? $limit : $content; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment