Created
July 10, 2017 09:48
-
-
Save braddalton/5d0be47605b3d609b80407c720c9855e 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="register-link"><a href="%s">Register</a> or login below to view all content.</h4></p>', esc_url( wp_registration_url() ) ); | |
$login_form .= sprintf( '<p class="login-form">%s</p>', wp_login_form( array( 'echo' => false ) ) ); | |
$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