Using WordPress ‘register’ PHP filter

‘register’ is a WordPress PHP filter that modifies the HTML link to the Registration or Admin page. When users visit the page, they’ll be redirected to the admin page if they are logged in, or to the registration page if they are logged out and registration is enabled.

Usage

add_filter('register', 'your_function_name');
function your_function_name( $link ) {
    return 'http://example.com/register/';
}

Parameters

  • $link (string):
    • The HTML code for the link to the Registration or Admin page.

Examples

function custom_registration_link_text($link) {
    return str_replace('Register', 'Sign Up', $link);
}
add_filter('register', 'custom_registration_link_text');

This code replaces the “Register” text in the registration link with “Sign Up”.

function custom_registration_link_url($link) {
    return str_replace(site_url('/wp-login.php?action=register'), 'https://yourwebsite.com/custom-register', $link);
}
add_filter('register', 'custom_registration_link_url');

This code replaces the default registration link URL with a custom URL.

function add_css_class_to_registration_link($link) {
    return str_replace('<a ', '<a class="custom-css-class" ', $link);
}
add_filter('register', 'add_css_class_to_registration_link');

This code adds a CSS class named “custom-css-class” to the registration link.

function hide_registration_link_for_logged_in_users($link) {
    if (is_user_logged_in()) {
        return '';
    }
    return $link;
}
add_filter('register', 'hide_registration_link_for_logged_in_users');

This code hides the registration link for users who are already logged in.

function add_custom_attribute_to_registration_link($link) {
    return str_replace('<a ', '<a data-custom-attribute="custom-value" ', $link);
}
add_filter('register', 'add_custom_attribute_to_registration_link');

This code adds a custom attribute named “data-custom-attribute” with a value of “custom-value” to the registration link.