WordPress User login Log out after redirection to the specified page implementation method

Source: Internet
Author: User

One, redirect to the Web Site Administration panel.

Add the following code to the functions.php file for your current topic:
PHP Code 1. function Soi_login_redirect ($redirect _to, $request, $user)
0.9
3. Return (Is_array ($user->roles) && in_array (' Administrator ', $user->roles))? Admin_url (): Site_url ();
4.}
5.add_filter (' Login_redirect ', ' soi_login_redirect ', 10, 3);

Redirect to a specific page or article

You can also redirect users to a specific page with the following code:
PHP Code 1. function Login_redirect ($redirect _to, $request, $user) {
2. Return Home_url (' custom-page ');
3.}
4.add_filter (' Login_redirect ', ' login_redirect ', 10, 3);
Modify Custom-page in code for a page or article link (note: Do not include the site domain name), if deleted custom-page will jump directly to the site home page.

Third, customize the redirect link after logout

PHP Code 1 add_action (' wp_logout ', ' auto_redirect_after_logout ');     
2.function Auto_redirect_after_logout () {     
3.  wp_redirect (Home_url ());      
4.  exit ();     
5.}  
 
to jump to the home page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.