How to Redirect Users to a Specific Page After Registration in WordPress
When developing WordPress themes or front-end login functionality, you often need to control where users are redirected after successful registration. Instead of the default login page, you might want to send them to a welcome page, profile page, or specific marketing page. This can be achieved by adding a simple code snippet.
Method 1: Using the registration_redirect Filter (Recommended)
This is the most standard and direct method. Add the following code to your current theme's functions.php file.
// Redirect after successful registration
function my_custom_registration_redirect() {
// Example 1: Redirect to home page
// return home_url();
// Example 2: Redirect to a custom URL
// return 'https://www.yourdomain.com/welcome/';
// Example 3: Redirect to a specific page (e.g., page ID 123)
// return get_permalink(123);
// Example 4: Redirect to user profile (requires plugin/theme support)
// return bp_loggedin_user_domain(); // For BuddyPress
// Default: Redirect to /welcome/ page
return home_url('/welcome/');
}
add_filter('registration_redirect', 'my_custom_registration_redirect');
Code Explanation & Notes:
- Function Naming: Use a unique prefix (like
my_custom_) to avoid conflicts with core or plugin functions. - Return Value: The function must return a valid URL string. Use WordPress functions like
home_url(),site_url(), orget_permalink()to generate links dynamically. - Scope: This filter works with the default registration process via
wp-login.php?action=register.
Method 2: Using Login/Registration Plugins
If you use a front-end login/registration plugin (e.g., Ultimate Member, ProfilePress, WooCommerce), these often provide built-in options for post-registration redirects in their settings. Check your plugin's settings panel first.
Troubleshooting Common Issues
- Code Not Working: Ensure the code is correctly added to
functions.phpand has no syntax errors. For debugging, adderror_log('Redirect function called');at the start. - Caching Issues: Clear any object or static caching after making changes.
- Conflicts: If your theme or another plugin also modifies this redirect, conflicts may occur; the last loaded code usually takes effect.
Using these methods, you can easily guide new users to any desired page, improving user experience and conversion rates.