Redirect after Login on WordPress

后端 未结 13 3038
我寻月下人不归
我寻月下人不归 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:01

    The accepted answer is very wrong. One should never be modifying the WordPress Core. Not only will edits be lost at a given update, some changes you make on a whim may compromise other functionality or even endanger the security of your site.

    Action Hooks & Filters are included within the core to allow modifying functionality without modifying code.

    An example of using the login_redirect filter to redirect certain users can be found here and is a much more robust solution to your problem.

    For your specific problem, you want to do this:

    function login_redirect( $redirect_to, $request, $user ){
        return home_url('news.php');
    }
    add_filter( 'login_redirect', 'login_redirect', 10, 3 );
    

提交回复
热议问题