I want to hide certain categories in my WordPress blog for the public but those that can be viewed by logged in user.
If public goes to visit a restricted category, they should be shown a login box where they must login to view the category
I have the is_user_logged_in function for WordPress but don't know how to use it for this purpose. What should I add to my functions.php?
I have tried this code, but can;t get it to work:
add_action( 'init', 'check_redirect_page' );
function check_redirect_page() {
if ( !is_user_logged_in() && !is_category( 177 ) ) {
wp_redirect( home_url( '/login' ) );
exit();
}
}
Does anyone have any other suggestions? It just won't work for me :(