How can i Re-Direct Members after Login

How can i Re-Direct Members after Login to a specific page depending on their access level. or in general.

Im using membershiplogin short code. need them to a specific page after login.

Thanks in advance for the help
Cheers
Alex

  • Ash

    Hello @elpino

    I hope you are well today and thanks for asking the question.

    Please use the following code:

    function admin_default_page() {
        if(is_user_logged_in()){
            if(current_user_on_level($id)){
                return URL;
            }
            elseif(current_user_on_level($id)){
                return URL;
            }
            else{
                return URL;
            }
        }
    }
    
    add_filter('login_redirect', 'admin_default_page');

    Here, $id is different level id, that you may want to put. And replace URL with your desired url.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always.

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers
    Ash

  • elpino

    @Ashok Hi there what should i put were the id is? i tried these 3 opcions and got errors ($id asociados) or (asociados) ($id 'asociados')

    i use following code with above variations and get errors

    `<?php
    function admin_default_page() {
    if(is_user_logged_in()){
    if(current_user_on_level($IDvisitors)){
    return 'http://mywebsite.com/wikis/';
    }
    elseif(current_user_on_level($IDasociados)){
    return 'http://mywebsite.com/wikis/wiki/cms/wordpress-101/wordpress-plugins/';
    }
    else{
    return 'http://mywebsite.com/wikis/';
    }
    }
    }

    add_filter('login_redirect', 'admin_default_page');

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.