Redirect a WordPress User to a Page Once per Session (No Plugins)

Sometimes a WordPress site owner may want to redirect logged-in users to a certain page—but only once per session. This can be helpful in a wide variety of scenarios: showing a custom welcome page, directing users to a new feature, or highlighting a special promotion. Achieving this without slowing down your website using additional plugins is ideal for performance and security. Fortunately, this can be implemented using a combination of PHP and JavaScript, and in this guide, we’ll walk through an effective, manual method to redirect WordPress users once per session—completely without plugins.
Why Redirecting Users per Session Matters
Using session-based redirects offers more control over user experience without coming across as disruptive or annoying. Imagine a situation where:
- You want to notify logged-in users about updated privacy policies.
- You want to promote a limited-time offer only once per visit.
- You want to welcome users with a custom dashboard or onboarding page.
Performing this redirection once per session ensures users see the message but aren’t constantly interrupted as they navigate your site. This process respects user experience, keeps your branding consistent, and improves overall engagement.
Step-by-Step Guide to Redirecting Once Per Session
This solution is divided into several parts. We will utilize:
- A small PHP function to detect a logged-in user.
- Browser sessionStorage via JavaScript to ensure the redirect happens only once per session.
- Optional CSS or HTML tweaks for layout adjustments on the redirection page.
Let’s walk through the process.
Step 1: Choose or Create the Redirection Page
Decide which page you’d like users to be redirected to. You can use an existing page or create a new one within WordPress. Take note of the page’s URL, as you’ll reference this during the JavaScript redirect.
Let’s say your URL is:
/welcome/
Ensure the page is published and accessible to users who are logged in. You might want to mark it as “Private” in WordPress and adjust permissions as needed so that only registered users can view it.

Step 2: Add JavaScript for Session-Based Redirection
Next, you’ll add a JavaScript snippet that checks if the user has already been redirected during the current session. You can place this code in your WordPress theme’s footer.php file or enqueue it properly within a child theme or custom plugin if you’re comfortable with that approach.
Below is a simple session-based redirect using JavaScript:
<script>
document.addEventListener("DOMContentLoaded", function() {
// Ensure the user is logged in by verifying a WordPress-specific class on the body tag
if (document.body.classList.contains("logged-in")) {
// Check sessionStorage to see if the user has already been redirected
if (!sessionStorage.getItem("redirected_to_welcome")) {
// Prevent redirection loop
if (window.location.pathname !== "/welcome/") {
sessionStorage.setItem("redirected_to_welcome", "true");
window.location.href = "/welcome/";
}
}
}
});
</script>
This script does the following:
- Checks if the user is logged in by detecting the
logged-in
body class WordPress automatically adds. - Uses
sessionStorage
to store a flag for the current browser session. - Redirects the user to
/welcome/
only if they haven’t already been redirected during this session and are not already on that page.
Note: sessionStorage
only persists as long as the browser session is active. Once the tab is closed, it resets, allowing the redirect again next time they visit in a new session.
Step 3: Adding the Script Safely
To incorporate the script without modifying your main theme files (for example, if you’re avoiding touching footer.php), you can enqueue it via your theme’s functions.php file.
Here’s how to enqueue a custom JavaScript inline in functions.php:
function custom_session_redirect_script() {
if ( is_user_logged_in() ) {
?>
<script>
document.addEventListener("DOMContentLoaded", function() {
if (!sessionStorage.getItem("redirected_to_welcome") && window.location.pathname !== "/welcome/") {
sessionStorage.setItem("redirected_to_welcome", "true");
window.location.href = "/welcome/";
}
});
</script>
<?php
}
}
add_action('wp_footer', 'custom_session_redirect_script');
This adds the redirect script only into the footer of pages viewed by users who are logged in.
Important Considerations
While this approach is lightweight and effective, there are a few caveats to keep in mind:
- Session Scope: This only works for the current browser session. Closing the tab or browser resets the redirect.
- Page Caching: If you’re using aggressive caching mechanisms, you may need to adjust how user-specific scripts are served.
- Single-Page Application (SPA) Sites: This method assumes traditional page loads. For Ajax-based navigation, you’ll need a more advanced solution.
Optional Enhancement: Conditional Roles
Want to redirect only specific types of users, such as Subscribers or Customers? Simply extend the conditional logic in functions.php like so:
if ( current_user_can('subscriber') ) {
// Add your script here
}
This ensures that only users with the subscriber role are redirected, giving you more site-wide control over the user experience.

Use Case Ideas for Session Redirects
Session-based redirects can serve various business and usability needs. Here are a few use cases:
- Onboarding Pages: Introduce new features or tutorials when a user logs in.
- Surveys or Polls: Encourage feedback once per session.
- Policy Updates: Require acknowledgment of terms or privacy changes.
- Time-Sensitive Offers: Highlight temporary promotions exclusively to existing users.
Security and Performance
Because we are not storing any personal data in sessionStorage, this method complies with most privacy policies and is safe from a GDPR perspective. It also avoids overloading the server since everything is handled client-side.
That said, never perform critical redirects based solely on JavaScript. For example, don’t depend on this method to protect sensitive areas or prevent access, as savvy users could circumvent client-side code. Always validate permissions server-side if necessary.
Conclusion
Redirecting a user once per session in WordPress without plugins is not only achievable—it’s efficient. By using a combination of PHP and JavaScript, you maintain full control over the user experience, bypass plugin bloat, and ensure your site runs smoothly. This technique is perfect for targeted messaging, onboarding flows, and temporary announcements, and it scales well with a WordPress site’s existing infrastructure.
By employing client-side session awareness via sessionStorage
, you ensure that the redirect does not occur repeatedly throughout the session while still retaining flexibility for future customization based on roles or behaviors. Use this strategy carefully, and your users will appreciate the seamless, professional experience your site provides.