WordPress – Hide pages for non-logged-in users

 In IT_Consultant_Singapore

Use this code on your child theme’s functions.php file..

//Hide for non-logged-in users (public visitors)
function bp_logged_out_page_template_redirect() { if( ! is_user_logged_in() && is_page( 'members' )|| is_page( 'activity' ) || bp_is_user() ) { wp_redirect( home_url( '/register/' ) ); exit(); } } add_action( 'template_redirect', 'bp_logged_out_page_template_redirect' );

The above snippet will do:

  • IF the user is not logged-in..
  • AND the page name is ‘members’ OR ‘activity’ OR bp-profile-page..
  • THEN it will redirect to REGISTER page.
Recent Posts