Overwriting the “Register” link

In a previous blog post, I wrote about how I used Gravity Forms to register users. This was done on a static page and not on the default WordPress registration page. When you want users to register using a different form, you should link to this page on many different places. In this blog post I want to show you how you can link to your own registration page from the login page.

The WordPress login page

In the “General Settings” you can activate the “Membership” option “Anyone can register” so that anyone can find a link on the login page that links to the default registration page:

The WordPress login page

If you just want to overwrite the URL of that link, you can use a filter. This get passed the HTML code of the link, which you can overwrite like this:

function custom_register_link( $link ) {
	return sprintf(
		'<a href="%s">%s</a>',
		esc_url( '/register/' ),
		esc_html__( 'Register' )
	);
}
add_filter( 'register', 'custom_register_link' );

This will set the link to the static URL /register/ using the default link text.

This approach only work then you have activated the registrations in the settings. But this would also make the default registration form available. If you haven’t activated the registration, you can still use Gravity Forms (or probably other plugins) to register users. But as the “Register” link is completely removes, you cannot simply overwrite its URL. In this case, we can also place a link on a different place using the following code:

function custom_login_site_html_link( $home_link ) {
	$register_link = sprintf(
		'<a href="%s">%s</a>',
		esc_url( '/register/' ),
		esc_html__( 'Register' )
	);

	return sprintf(
		'%s<br /><br />%s',
		$register_link,
		$home_link
	);
}
add_filter( 'login_site_html_link', 'custom_login_site_html_link' );

This filter is usually used to hook into the “← Go to <sitename>” link. This is the only place we can insert a custom link into. The result would look like this:

The WordPress login page with a custom “Register” link

This link might even be a bit more visible than the link on the default position, just before the “Lost your password?” link.

Conclusion

Allowing users to register themselves with your own registration form can really be beneficial. If you use a custom form, then make sure to always link users to this form.

Posted by

Bernhard is a full time web developer who likes to write WordPress plugins in his free time and is an active member of the WP Meetups in Berlin and Potsdam.

Leave a Reply

Your email address will not be published.