Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created July 10, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/f125b2e5dff82ea24e9ac7c086a298df to your computer and use it in GitHub Desktop.
Save braddalton/f125b2e5dff82ea24e9ac7c086a298df to your computer and use it in GitHub Desktop.
Hide Posts From Logged Out Users https://wp.me/p1lTu0-gTu
<?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