Redirect WordPress user

This the second tutorial and by starting it slow I am going to show you a small handy function that you will love!

This snippet allows you to redirect login users and check on what WordPress page they currently at. This is useful when you run a Membership website and want your members redirected only to the member’s area and restrict access for some users.

In the previous post, I showed you how to create a child theme and explain what type of files you can add in your child theme. One of the files is “functions.php”.

  1. Open your Child Theme folder and create a file called “functions.php”
  2. Now copy and paste the code below into your functions file.
  3. Replace the is_page( Your Page ID ) with the page you want. For example, when your members land on the home page and they are logged in, redirect them to the member’s area.
    1. To get your page ID read more here.
  4. Replace “/dashboard” with the page you want.
    1. This is the slug of your page.

[snippet slug=redirect-user lang=php]

Post a comment