I have a button that I have that leads users to a page on WordPress called /portfolio/
, so is there a way that I can redirect users to the /registration/
page until their logged in?
I'm using a plugin on WordPress that uses the below code to change the menu per user logged in/logged out.
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Is there a way that I can use the if( is_user_logged_in() )
to do the same with a redirect? I can't seem to lock the page down to all users.
I have a button that I have that leads users to a page on WordPress called /portfolio/
, so is there a way that I can redirect users to the /registration/
page until their logged in?
I'm using a plugin on WordPress that uses the below code to change the menu per user logged in/logged out.
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Is there a way that I can use the if( is_user_logged_in() )
to do the same with a redirect? I can't seem to lock the page down to all users.
You'll need to find out what theme template file is being used to display the /portfolio/
page - page.php
, page-portfolio.php
, tpl-portfolio.php
, or something along those lines.
Then, if you don't already have a child theme, create one.
Then, copy the template file into your child theme, and at the very top - before anything else - add:
// If the user is not logged in
if( !is_user_logged_in() ) {
// send them to the login screen
// once they log in, they will automatically return to this page
auth_redirect();
} else {
// move all your other code into this condition
}
As the comments note, if the user isn't logged in, they'll be redirected to the login page. Once they are logged in, they'll be redirected back to the portfolio page.