WPThumbs
Themes Plugins By purpose By industry Best-of lists Fix it guides
Free Plugin by Daan Kortenbach v1.7.0

Redirect to login if not logged in

Redirects users to the login page if the visitor is not logged in.

Redirect to login if not logged in

The facts

Rating
4.8★ from 10
Active installs
200+
Price
Free
Last updated
13 Sep 2018
Added
Jun 2013
Requires WP
3.0.1
Tested up to
WP 5.0.27
Downloads
20,185

Our analysis

AI-assisted

Redirect to login if not logged in is a WordPress plugin that redirects users to the login page when they are not logged in. Once a user logs in, they are sent back to the page they originally tried to access. The plugin includes a filter for advanced users, allowing them to set conditions for overriding the redirect behaviour.

This plugin is suitable for sites where you want to restrict access to logged-in users only. It is particularly useful for membership sites or private content areas, although it may not be the best choice for all scenarios, as a dedicated membership plugin might be more appropriate.

Best for: This plugin is best for websites that require user authentication for access.

What it does well

  • Redirects users to login page if not logged in
  • Sends users back to original page after login
  • Includes a filter for advanced users to override redirects

Where it falls short

  • Limited functionality beyond redirection
  • May not suit all types of websites

Verdict

Redirect to login if not logged in provides a straightforward solution for managing user access. It may be useful for specific use cases, but its simplicity could limit its appeal for more complex needs.

From the developer

Daan Kortenbach's own description of Redirect to login if not logged in, lightly tidied.

Redirects users to the login page if the user is not logged in. After login the user gets redirected to the original entry page. For advanced users a filter is provided to override the redirect.

The principle behind this plugin is to redirect all users – from every post, page, archive, etc. – to the login page (usually wp-login.php). Except for the override filter it does nothing else.

Overriding the redirect

  • Note: This plugin may not be for you, a membership plugin might be a better fit. Chris Lema writes excellent reviews of +30 membership plugins here: http://chrislema.com/category/memberships-plugins/

If you do have a need for this plugin and you want to exclude specific views under specific conditions, a filter is provided to override the redirect.

To override the redirect the filter must return a boolean value of true. WordPress core provides many conditional tags that either return true or false or you can write your own conditionals.

Take a look at the Conditional Tags page on The WordPress Codex for some inspiration.
https://codex.wordpress.org/Conditional_Tags

Usage:
Copy/paste/edit an example to the functions.php of your theme or create a new file in wp-content/mu-plugins/ if you do not wish to edit your theme.

Note: Be carefull not to use multiple filters at the same time as that may cause unexpected results. Instead use multiple conditions in one filter.

  • Override if the front page is either posts or a page:

    add_filter( ‘rtl_override_redirect’, ‘is_front_page’ );

  • Override if the post is ‘hello-world’:

    add_filter( ‘rtl_override_redirect’, function() {
    return is_single( ‘hello-world’ );
    });

  • Override if the page is ‘sample-page’:

    add_filter( ‘rtl_override_redirect’, function() {
    return is_page( ‘sample-page’ );
    });

  • Override if the page ID is 42, the slug is ‘sample-page’ or the title is ‘About Me’:

    add_filter( ‘rtl_override_redirect’, function() {
    return is_page( array( 42, ‘sample-page’, ‘About Me’ ) );
    });

  • Override if the page ID is 42 or a post is ‘hello-world’:

    add_filter( ‘rtl_override_redirect’, function() {
    if ( is_page( 42 ) || is_single( ‘hello-world’ ) ) {
    return true;
    }
    });

Read the full description on the official page →

Tagged as

Alternatives

Other plugins for managing URLs.

All in One SEO

AIOSEO is the WordPress SEO plugin. Boost SEO rankings with AI SEO tools, schema, meta descriptions, XML sitem...

Free 2M+ installs 4.7★ (5,201)
301 Redirects

Manage 301 & 302 redirects. Simple redirection & redirects validation. Includes redirect stats & 4...

Free 300k+ installs 4.7★ (578)
Redirection for Contact Form 7

Redirect to any page or URL, execute scripts after submission, save data to the database, and unlock additiona...

Free 200k+ installs 4.7★ (275)
Permalink Manager Lite

Permalink Manager enhances WordPress’s built-in URL system, allowing you to change the URLs of native and cust...

Free 100k+ installs 4.8★ (176)
WP Encryption

Lifetime SSL solution - Free SSL certificate & HTTPS redirect, fix insecure site / SSL errors, Security he...

Free 50k+ installs 4.9★ (1,143)
Redirection

Manage 301 redirects, track 404 errors, and improve your site. No knowledge of Apache or Nginx required.

Free 2M+ installs 4.4★ (703)