A WordPress plugin that automatically redirects users back to the page they were viewing before login, using cookie-based tracking.
The ODR WordPress Login Redirect plugin enhances the user experience by remembering where users were on your site before they logged in. After successful authentication, users are automatically redirected back to their previous location instead of the default WordPress admin dashboard.
- Automatic Page Tracking: Uses JavaScript to set a cookie with the current page URL on every visit
- Smart Redirect: After login, users are redirected to their previous page
- AJAX Support: Tracks URL hash changes for single-page applications
- Custom Login Logo: Replace the WordPress logo on the login page with your own image
- Security First: Validates all redirect URLs to prevent open redirect vulnerabilities
- Configurable: Admin settings panel for customization
- Debug Mode: Built-in debugging tools for troubleshooting
- Exclusion Rules: Automatically excludes login, admin, and password reset pages
- Custom Exclusions: Add your own pages to exclude from tracking
- Upload the
odr-login-redirectfolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Configure settings at Settings > ODR Login Redirect
Navigate to Settings > ODR Login Redirect in your WordPress admin to configure:
- Enable Plugin: Toggle the redirect functionality on/off
- Cookie Expiry: Set how long the redirect cookie remains valid (1-168 hours, default: 24 hours)
- Excluded Pages: Add URLs or URL fragments that should not trigger redirects
- Debug Mode: Enable console and error log debugging for troubleshooting
- Page Visit: When a user visits any page (except excluded pages), JavaScript sets a cookie with the current URL
- Login Page: When the user reaches the login page, the plugin reads the cookie value
- Authentication: After successful login, WordPress redirects to the URL stored in the cookie
- Cleanup: The cookie is cleared after use to prevent unwanted future redirects
- Name:
odr-wordpress-login-redirect - Default Expiry: 24 hours
- Scope: Site-wide (path:
/) - Security: Uses Secure flag on HTTPS, SameSite=Lax
The following pages are automatically excluded from redirect tracking:
/wp-login.php/wp-admin/*/wp-register.php/wp-activate.php/wp-signup.php- Password reset pages
- Logout URLs
You can add custom exclusions in the plugin settings.
- Domain Validation: Only redirects to the same domain (prevents open redirect attacks)
- URL Sanitization: All URLs are properly sanitized and validated
- Nonce Protection: Admin settings use WordPress nonce verification
- Secure Cookies: Uses secure cookie flags when on HTTPS
- Enable Debug Mode in plugin settings
- Open browser developer console (F12)
- Visit any page on your site
- Check console for "[ODR Login Redirect]" messages
- Log out of WordPress
- Log back in - you should be redirected to the page from step 3
- Check console and PHP error logs for debug information
- Ensure the plugin is enabled in settings
- Check if JavaScript is enabled in your browser
- Verify cookies are not being blocked
- Enable Debug Mode and check console/error logs
- Check the Excluded Pages setting
- Clear browser cookies and try again
- Enable Debug Mode to see which URL is being stored
- Check browser console for JavaScript errors
- Verify the page is not in the excluded list
- Ensure cookies are enabled in the browser
The plugin uses the following WordPress hooks:
wp_enqueue_scripts- Enqueue public JavaScriptlogin_enqueue_scripts- Add scripts to login pagewp_login- Clear cookie after loginadmin_menu- Add settings pageadmin_init- Register settings
login_redirect- Handle the actual redirectplugin_action_links_*- Add settings link to plugins page
odr-login-redirect/
├── admin/
│ ├── class-odr-wp-login-redirect-admin.php
│ └── partials/
│ └── odr-wp-login-redirect-admin-display.php
├── includes/
│ ├── class-odr-wp-login-redirect.php
│ ├── class-odr-wp-login-redirect-loader.php
│ ├── class-odr-wp-login-redirect-activator.php
│ └── class-odr-wp-login-redirect-deactivator.php
├── public/
│ ├── class-odr-wp-login-redirect-public.php
│ └── js/
│ └── odr-wp-login-redirect-public.js
├── odr-wp-login-redirect.php
├── uninstall.php
└── README.md
ODR_WP_LOGIN_REDIRECT_VERSION- Plugin versionODR_WP_LOGIN_REDIRECT_BASENAME- Plugin basenameODR_WP_LOGIN_REDIRECT_PATH- Plugin directory pathODR_WP_LOGIN_REDIRECT_URL- Plugin directory URLODR_WP_LOGIN_REDIRECT_COOKIE- Cookie name
- WordPress 5.0 or higher
- PHP 7.4 or higher
- JavaScript enabled in browser
- Cookies enabled in browser
For support or to report issues, please visit opendatarepository.org
This plugin is licensed under GPL-2.0+. See LICENSE.txt for details.
Developed by Open Data Repository
- Added custom login logo feature
- Users can replace WordPress logo on login page with image from media library
- Configurable logo dimensions (width/height)
- Option to link logo to site homepage
- Added media library selector in admin settings
- Added
hashchangeevent listener to track URL changes when AJAX content loads - Refactored URL exclusion logic to support checking any URL
- Added support for custom excluded pages/fragments in JavaScript
- Initial release
- Cookie-based redirect tracking
- Admin settings panel
- Debug mode
- Security validations