Change register form action url

by Minimus   Last Updated September 21, 2018 16:08 PM

I have 2 registration forms, default one on /wp-login.php?action=register for "recruiter" users, other one on /wp-login.php?action=register&type=candidat for "candidates" users

My problem is that on candidate form, the form tag still has /wp-login.php?action=register as the action URL, and I want it to be /wp-login.php?action=register&type=candidat

I tried updating wp-login.php file but if I update Wordpress in the future, my code will be overwritten

I've tried other topics recommanding to use 'register_url' hook but it doesn't seem to work

Answers 2

You could do something like this:


add_action( 'register_form', function() {
    $get_type = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING );

    if ( ! $get_type ) {
<input type="hidden" name="type" value="<?php echo esc_attr( $get_type ); ?>" />

This will add the type parameter as a hidden field on the form if it is set in the GET query string.

September 21, 2018 20:22 PM

I went a different route than the other answer, a modification of the registration URL through the site_url filter, I've tested it, and it works.

function my_verify_registration_type( $url, $path, $scheme, $blog_id ) {
    if ( $scheme == 'login_post' ) {
        if ( strpos( $url, '?action=register' ) !== false && !empty( $_REQUEST['type'] ) ) {
            $url = esc_url( add_query_arg( 'type', sanitize_text_field( $_REQUEST['type'] ), $url ) );
    return $url;
add_filter( 'site_url', 'my_verify_registration_type', 10, 4 );
September 21, 2018 20:35 PM

Related Questions

Where to put a custom user login / register form?

Updated November 09, 2018 12:08 PM

Login user after registration programmatically

Updated November 11, 2018 09:08 AM