Redirect after Login on WordPress

后端 未结 13 3029
我寻月下人不归
我寻月下人不归 2020-12-04 11:26

I\'m creating a customized WordPress theme based on an existing site.

I want to use an alternate dashboard which I have created.

How can I have the user dire

相关标签:
13条回答
  • 2020-12-04 12:06

    Please try this, it works for any redirection on WordPress

    add_filter('woocommerce_login_redirect', 'wc_login_redirect'); 
    
    function wc_login_redirect( $redirect_to ) {
    
       $redirect_to = 'PUT HERE URL OF THE PAGE';
       return $redirect_to;
    
    }
    
    0 讨论(0)
  • 2020-12-04 12:09
    // add the code to your theme function.php
    //for logout redirection
    add_action('wp_logout','auto_redirect_after_logout');
    function auto_redirect_after_logout(){
    wp_redirect( home_url() );
    exit();
    }
    //for login redirection
    add_action('wp_login','auto_redirect_after_login');
    function auto_redirect_after_login(){
    wp_redirect( home_url() );
    exit();
    `enter code here`}
    
    0 讨论(0)
  • 2020-12-04 12:10

    The accepted answer is clearly not a good answer! It may solve your problem for a while, but what will happen next time you update your WordPress installation? Your core files may get overridden and you will loose all your modifications.

    As already stated by others (Dan and Travis answers), the correct answer is to use the login_redirect filter.

    0 讨论(0)
  • 2020-12-04 12:11

    You can also use the customized link as:

    https://example.com/wp-login.php?redirect_to=https://example.com/news.php
    
    0 讨论(0)
  • 2020-12-04 12:11

    To globally redirect after successful login, find this code in wp-login.php, under section.

       <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
    
    <input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
    

    and replace <?php echo esc_attr($redirect_to); ?> with your URL where you want to redirect. The URL must start with http:// and ends on /other wise page redirect to default location.

    Do same thing form redirect after registration with in same file but under <form name="registerform"> section.

    0 讨论(0)
  • 2020-12-04 12:12

    The Theme My Login plugin may help - it allows you to redirect users of specific roles to specific pages.

    0 讨论(0)
提交回复
热议问题