To create a seamless experience for the site users, you can use Toolset to create custom login pages.
- What you’ll need
- Create a template for the login form
- Set the login form to appear only for visitors
- Insert the link to the „Lost password“ page
- Hide pages from users and menus
- Redirect users after they log in
Besides Toolset Blocks and Toolset Types plugins, you need to have the Toolset Access plugin installed in your site.
When non-logged-in users reach the users reach the „My Account“ page, we want to provide a login form.
- Go to Toolset → Content Templates.
- Create a new template. Name it Login Form and don’t assign it to any post type.
- Add the Fields and Text block to this template.
- Click the Add Field or View button.
- Locate and click the Login form button.
- The Login Form dialog opens. Leave the default options and click to insert the shortcode.
You can’t get a preview of the form on the backend as it can only works from the front-end.
You will display this template to non-logged-in users instead of the “My Account” page.
Now, you need to configure the login form template to appear on the “My account” page for users that are not logged in.
- Navigate to Toolset → Access Control.
- Click the Post Groups tab.
- Create a group Logged-in users only.
- In the Guest row, deselect the checkbox in the Read column. Then, click the pencil icon and a pop-up dialog will appear.
- Select Show Content Template. Here, for users with restricted access, you can select a template to display instead of the page content.
- Choose Login Form, which is the name of the layout we just created.
- Click the Set errors button to save your changes.
- Save your post group.
Now, the “My Account” page should show the login form for the users that are not logged in.
To help users in case they forget their password, you can set up the „Lost password“ page. Once you have it, simply link to it from the „My Account“ page.
To complete our “My Account” page project, we offer one final suggestion. Some pages apply only to visitors, for example „Lost password“, „Reset password“, and „Create account“.
It’s best to hide these pages from all logged-in users, thus making them available only for guests.
When you hide pages from users by using Post Groups, they will also automatically be hidden for these users in the menus.
Learn how to do this in our lesson about hiding pages from menus and users in WordPress.
After logging into the site, users should end up on a meaningful page. On directory or membership sites, taking them to their account page makes sense.
You can easily do this by using an additional plugin. In our example, we’ll use the Peter’s Login Redirect plugin to accomplish this. After installing the plugin, do the following:
- Go to the Settings → Login/logout redirects page. In our case, we want to add a redirect for a specific role so we’ll use the Specific roles section.
- Specify the user role you want to redirect after login.
- In the URL field, enter the page you want users to end up at after logging in.
- In the Logout URL field, enter the page you want users to end up at after logging out.
- Click the Add role rule button to confirm your selection.
At the next login, users with the selected role will go to the specified URL.