The ‘registration_redirect’ filter allows you to modify the URL that users are redirected to after successfully registering on your WordPress site.
Usage
To use this filter, you need to create a custom function and hook it to the ‘registration_redirect’ filter. Here’s a code example:
function my_custom_registration_redirect( $registration_redirect, $errors ) { // Your custom code here } add_filter( 'registration_redirect', 'my_custom_registration_redirect', 10, 2 );
Parameters
- $registration_redirect (string) – The URL where users will be redirected after registration.
- $errors (int|WP_Error) – The user ID if registration was successful, or a WP_Error object if registration failed.
Examples
Redirect users to a custom thank you page
function custom_thank_you_page( $registration_redirect, $errors ) { return home_url( '/thank-you/' ); } add_filter( 'registration_redirect', 'custom_thank_you_page', 10, 2 );
In this example, after registration, users will be redirected to a custom thank you page on your site.
Redirect users to their profile page
function redirect_to_profile_page( $registration_redirect, $errors ) { return get_author_posts_url( $errors ); } add_filter( 'registration_redirect', 'redirect_to_profile_page', 10, 2 );
After successful registration, this code will redirect users to their profile page.
Redirect users to a specific page based on their role
function redirect_based_on_role( $registration_redirect, $errors ) { $user = new WP_User( $errors ); if ( in_array( 'subscriber', $user->roles ) ) { return home_url( '/subscriber-dashboard/' ); } return $registration_redirect; } add_filter( 'registration_redirect', 'redirect_based_on_role', 10, 2 );
In this example, subscribers are redirected to a custom dashboard page after registration.
Redirect users to a custom page if registration fails
function redirect_on_failed_registration( $registration_redirect, $errors ) { if ( is_wp_error( $errors ) ) { return home_url( '/registration-error/' ); } return $registration_redirect; } add_filter( 'registration_redirect', 'redirect_on_failed_registration', 10, 2 );
This code redirects users to a custom registration error page if their registration fails.
Redirect users to the homepage with a custom query parameter
function redirect_with_custom_query( $registration_redirect, $errors ) { return home_url( '/?registered=true' ); } add_filter( 'registration_redirect', 'redirect_with_custom_query', 10, 2 );
In this example, users will be redirected to the homepage with a custom query parameter (?registered=true
) after registration.