Skip to content
Back to skills

Login Redirector

ASecurity

Handle WordPress login/logout redirects. Use when implementing custom redirect logic.

  • 666 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 9, 2026
developmentgophp

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill login-redirector --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Login Redirector?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Login Redirector
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-login-redirector/badge)](https://www.skillsdirectory.com/skills/majiayu000-login-redirector)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: login-redirector
description: Handle WordPress login/logout redirects. Use when implementing custom redirect logic.
---

# Login Redirector

## Instructions

When setting up login or logout redirects:

1. **Login redirect**: Use `login_redirect` filter
2. **Logout redirect**: Use `logout_redirect` filter
3. **Parameters**: Both receive `$redirect_to`, `$request`, `$user`
4. **Return the redirect URL**

## Filter Parameters

```php
add_filter('login_redirect', $callback, 10, 3);
add_filter('logout_redirect', $callback, 10, 3);

/**
 * @param string $redirect_to The redirect destination URL
 * @param string $request The requested redirect destination URL
 * @param WP_User|WP_Error|null $user The logged-in user or error
 */
```

## Common Patterns

### 1. Redirect by User Role

```php
add_filter('login_redirect', 'retrologin_redirect_by_role', 10, 3);
function retrologin_redirect_by_role(string $redirect_to, string $request, $user): string {
    if ($user instanceof WP_User) {
        if (user_can($user, 'administrator')) {
            return admin_url();
        }
        return home_url('/dashboard/');
    }
    return $redirect_to;
}
```

### 2. Keep Requested URL

```php
add_filter('login_redirect', 'retrologin_keep_request', 10, 3);
function retrologin_redirect_keep_request(string $redirect_to, string $request, $user): string {
    // Use the page they were trying to access
    if (!empty($request) && strpos($request, 'wp-admin') === false) {
        return $request;
    }
    return $redirect_to;
}
```

### 3. Custom Logout Redirect

```php
add_filter('logout_redirect', 'retrologin_logout_redirect', 10, 3);
function retrologin_logout_redirect(string $redirect_to, string $requested_redirect_to, $user): string {
    return home_url('/thank-you/');
}
```

## Guidelines

-   Always check if `$user` is a valid WP_User
-   Handle WP_Error cases (failed login)
-   Return `$redirect_to` as fallback
-   Test redirects with different user roles

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.