1

So I have this button on the menu : "My account" that lets the user login on the website and as soon they log in they're redirect to their dashboard.

What I'm trying to achieve is if he's logged in and presses again the "My account" button to be redirect to the dashboard, because right now is redirecting to there account settings.

 add_action( 'template_redirect', 'dashboard_redirect' );
function dashboard_redirect()
{
    if( is_page( home_url( '/min-konto/' ) ) && ! is_user_logged_in() )
    {
        wp_redirect( home_url( '/dashboard/' ) );
        exit();
    }
}

I'm kinda new to WP.

1 Answer 1

0

Firest of all you have to make sure that is_page() is right. I think the right syntax is

is_page( 'min-konto' )

or

is_page($pageid)

then the function should be

if( is_page( $account_settings_page_id ) && is_user_logged_in() ) {
   wp_redirect( home_url( '/dashboard/' ) ); 
exit(); 
}
15
  • I did tried like is_page( 'min-konto' ) and ( 'myaccount ' ) because that's the slug in english , but not with is_page($pageid), how i can find out the pageid ?
    – Remus
    Jan 29, 2016 at 12:21
  • Never mind about the pageid , I did found it and try it now
    – Remus
    Jan 29, 2016 at 12:28
  • I suppose that 'min-konto' is the slug of the page from which you want the non logged in users to be redirected to the page with the permalinnk : www.sxample.com/dashboard
    – Silenced
    Jan 29, 2016 at 12:29
  • I want the logged in user to be redirect to www.sxample.com/dashboard when they pressed the button My account, that is the same button they use to log in in their account
    – Remus
    Jan 29, 2016 at 12:32
  • add_filter('woocommerce_login_redirect', 'login_redirect', 10, 2); function login_redirect( $redirect_to, $user ) { // WCV Pro Dashboard if (class_exists('WCV_Vendors') && class_exists('WCVendors_Pro') && WCV_Vendors::is_vendor( $user->id ) ) { $redirect_to = get_permalink(WCVendors_Pro::get_option( 'dashboard_page_id' )); } return $redirect_to; } This is the function that I use to redirect the user to dashboard after they log in
    – Remus
    Jan 29, 2016 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.