2

How to redirect the user with role Editor to their respective dashboard after register?

Here is the Ajax Script:

wp_localize_script('jquery_login','ajax_object',array('ajax_url'=>admin_url('admin-ajax.php'),'redirecturl' => get_dashboard_url()));

The Ajax Code:

success: function(data){
    if(data.reg==true){
    jQuery('#reg_message').prepend('Register Successfully. Redirecting...');
    window.setTimeout(function(){
    document.location.href = ajax_object.redirecturl;
    }, 2000);
}

I also tried this window.location.href = ajax_object.redirecturl; but the url redirect to admin login page.

  • To make sure of the redirect URL, see the output of redirecturl in your source. – Mostafa Soufi Jan 8 '18 at 8:01
  • It shows http://www.demo.com/wp-admin/ and redirects to login page. – DHL17 Jan 8 '18 at 9:11
  • Try to use my answer. – Mostafa Soufi Jan 8 '18 at 11:56
2

You should set your address with the static method. For example:

wp_localize_script(
    'jquery_login',
    'ajax_object', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'redirecturl' => get_bloginfo('url') . '/user/dashboard' // Your Address
    )
);
  • Not working same output redirects to admin login page. – DHL17 Jan 8 '18 at 12:03
  • Clear the browser cache and try to check. – Mostafa Soufi Jan 8 '18 at 20:02
  • What to add in // Your Address, I cant figure out. – DHL17 Jan 9 '18 at 4:50
  • You should set a path for redirection. for e.g. '/user/dashboard' or '/user/profile'. Then make sure about this hook in your WordPress login_redirect – Mostafa Soufi Jan 9 '18 at 7:29
  • it only works if u add function login_new_user( $user_id ) { wp_set_current_user( $user_id ); wp_set_auth_cookie( $user_id, false, is_ssl() ); } add_action( 'user_register', 'login_new_user' ); – DHL17 Jan 9 '18 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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