admin-plugins author calendar category facebook post rss search twitter star star-half star-empty

Tidy Repo

The best & most reliable WordPress plugins

Free Peter’s Login Redirect

Please read! This plugin has not been updated in over 6 months. It may no longer be maintained or supported. There may be compatibility issues when used with the latest version of WordPress. We suggest finding a similar, alternative plugin. Learn more about outdated plugins.

Peter’s Login Redirect

Plugin Author: Peter Keung

Jay Hoffmann

September 30, 2014 (modified on September 20, 2020)

Admin

When users log in or log out of WordPress they are taken to either the WordPress admin or login form, respectively. However, if you’ve opened up your site to members, or simply want a better experience for clients, then you may want to redirect users somewhere more specific after login. Peter’s Login Redirect gives you complete control over this.

What’s It Do?

Basically, Peter’s Login Redirect allows you to direct users anywhere on your site after they log in. This can be your site’s homepage, a specific page in the admin, or just about anywhere else. You can choose how to redirect users by their username, user role (administrator, editor, subscriber, etc.) or capabilities. You can also include a username variable in your redirect or a couple of other variables like postid. And finally, you have a bit of control over how the redirects work with a few extra settings.

The plugin also has a few filters to hook into if you want to customize the redirects a bit more or create your own variables.

And while we are on the topic of customization, you should make sure your login forms are custom as well. This can be achieved with the use of a plugin like HappyForms.

HappyForms

HappyForms is an intuitive plugin that enables anyone using it to build beautiful and eye-catching forms, sign-ups, surveys, polls, and checkouts, all with a live drag-and-drop builder.

All the forms created with this plugin can be managed and updated directly from one dashboard which can also be used to track form performance, display live results, and do a lot more.

After giving you that little tip, it’s time we get back to the Peter’s Login Redirect plugin review!

How’s It Work

After you install and activate the plugin, you can start managing the redirect rules by going to Settings -> Login/logout Redirects

You will see a few different ways to manage redirects. In each section, you will see a “URL” and a “Logout URL” text field. The URL is where you should put the location you want to redirect after login, the Logout URL field is for redirects after logout. There are a couple of variables you can use here as well. If you type [variable]username[/variable] in the text field, then the username will be inserted dynamically into the URL. You can also specify “homeurl” for the home URL, “siteurl” for your site’s homepage, and “postid-23” (replacing 23 with the post you want to redirect to).

The first section is Specific Users. Simply select a current user from the drop-down menu, and specify a login and logout URL, then click “add username rule”.

The next section is Specific Roles. Once again select a user role, like the editor, author or administrator, from the drop-down menu and specify a login and logout rule. Specific Levels works the same way, but allows you to select a specific capability, such as the ability to “publish_posts” or “manage_categories”. This is useful if you’ve structured your membership system based on capabilities rather then roles. In terms of precedence, the highest rule takes precedence over the sections below it. So Specific Users will override anything below it, and so on.

Peter's Login Redirect plugin

Redirecting “editor” users to the homepage

The “All Other Users” section is where you can specify a catch-all rule, that’s not specifically called out in the sections above. There is also a text field below this for “Post Registration”. Enter the URL here of where the users should be redirected to after they register for your site.

At the bottom of the settings page, there is also a separate section for “Customize plugin settings,” where you can set up Redirect Restrictions, and choose which higher level redirect rules should take precedence. Unless you understand how it works, it’s best to stay away from this section. You can also select who has the ability to edit redirect URL’s based on capability type. The default is “manage_categories”, but you can select any from the drop-down menu.

Peter's Login Redirect advanced settings

Advanced settings

There are also a couple of useful filters you can use to further customize the redirects. I won’t go into too much detail here, but the four filters available are rul_before_user, rul_before_role, rul_before_capability, and rul_before_fallback. There is also a matching filter for logout for each, with a “_logout” appended to the end of the filter name (rul_before_user_logout). These filters correspond to the chain of events according to the precedence of the redirect rules. So if you want to use a filter before any of your specified rules take effect, use rul_before_user. For instance, as a totally trivial example, let’s say I wanted to redirect all users with the first name “Jay” to a special URL. I just set up a function, passing the four included variables to it, and then add the filter.

function redirectByName( $custom_redirect_to, $redirect_to, $requested_redirect_to, $user )
{
    if( $user->first_name == "Jay" )
    {
        return '/special';
    }
    else
    {
        return $custom_redirect_to;
    }
}

add_filter( 'rul_before_user', 'redirectByName', 10, 4 );

Of course, there’s a lot more that can be done with this, so visit the installation instructions for a few more examples.

You can also add a custom variable that can be used within the [variable] syntax in URL. To do so, you can use the “rul_replace_variable” filter.

function customVariableReplace( $custom_redirect_to, $variable, $user )
{
    if( 'month' == $variable )
    {
        return date( 'm' );
    }
    else
    {
        return $custom_redirect_to;
    }
}

add_filter( 'rul_replace_variable', 'customVariableReplace', 10, 3 );

This will add the variable month, which can be used in any of your text fields as [variable]month[/variable].

For more information on how to properly use the included filters, you can check out the Other Notes section on the WordPress plugin page.

Costs, Caveats, Etc.

Peter’s Login Redirect is completely free, and well maintained with frequent updates. There are several translations available, and if you are having trouble with it, you can visit the dedicated support forums on the plugin developer’s site.

Resources

Plugin Info
  • Downloads: 2,406,599+
  • Downloads trend (30d): -9.9%
  • Active installations: 100,000+
  • Rating:
  • Last Update: August 25th, 2023
  • Download Plugin for Free