apply_filters( ‘register_url’, string $register ) is a WordPress PHP filter that lets you modify the user registration URL.
Usage
To use this filter, you can create a custom function, and then hook it to the register_url filter using the add_filter() function:
function my_custom_register_url( $register ) {
// Modify $register here
return $register;
}
add_filter( 'register_url', 'my_custom_register_url' );
Parameters
- $register (string)
- The user registration URL.
Examples
Redirect users to a custom registration page
function custom_registration_page_url( $register ) {
return home_url( '/custom-register/' );
}
add_filter( 'register_url', 'custom_registration_page_url' );
This code snippet changes the registration URL to a custom page named “custom-register” on your site.
Add a referral parameter to the registration URL
function add_referral_parameter( $register ) {
$referral_id = '1234';
return add_query_arg( 'ref', $referral_id, $register );
}
add_filter( 'register_url', 'add_referral_parameter' );
This code snippet adds a “ref” query parameter with a value of “1234” to the registration URL.
Change the registration URL based on user’s language
function change_register_url_based_on_language( $register ) {
$language = get_user_locale();
if ( $language === 'fr_FR' ) {
return home_url( '/inscription/' );
}
return $register;
}
add_filter( 'register_url', 'change_register_url_based_on_language' );
This code snippet redirects French users to a French registration page named “inscription”.
Redirect users to an external registration site
function redirect_to_external_registration( $register ) {
return 'https://external-registration-site.com';
}
add_filter( 'register_url', 'redirect_to_external_registration' );
This code snippet changes the registration URL to an external site.
Append a UTM parameter to the registration URL for tracking
function append_utm_parameter( $register ) {
return add_query_arg( 'utm_source', 'my_source', $register );
}
add_filter( 'register_url', 'append_utm_parameter' );
This code snippet adds a “utm_source” query parameter with a value of “my_source” to the registration URL for tracking purposes.