skip to Main Content

I have a custom registration page and working fine unless I am logged-in. When I am login and click on my registration page it takes me to the registration page but it is blank. I want it to redirect the user if he/she logged-in to the my account page.

2

Answers


  1. You can do it like this in your header.php

    $post = get_post();    
    if(is_user_logged_in()) {
            if($post->slug == 'regitrate-slug-here'){
                header( 'Location: /my-page-slug-here' );
            }
        }
    

    or just paste the link in the if statement

    if(is_user_logged_in()) {
        <a href="my-page">My page</a>
    } else {
        <a href="register">Register</a>
    }
    
    Login or Signup to reply.
  2. To Redirect custom Registration page to My Account page you should try small javascript something like this.

    Write this code in your php file that you have created for registration.

    if(is_user_logged_in()) {
        echo("<script>location.href = '".home_url('my-account')."'</script>");
        exit;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search