# Front-End Registration Form Shortcode

> Adds a [wpide_register] shortcode that shows a sign-up form on any page, styled by your theme, using WordPress's normal registration process and emails.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: registration, shortcode, form
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/frontend-registration-form/

## Code

```php
$wpide_register_errors = null;

add_action( 'template_redirect', function () use ( &$wpide_register_errors ) {
    if ( empty( $_POST['wpide_register_nonce'] ) || is_user_logged_in() ) {
        return;
    }

    if ( ! wp_verify_nonce( sanitize_key( $_POST['wpide_register_nonce'] ), 'wpide_register' ) ) {
        $wpide_register_errors = new WP_Error( 'nonce', 'The form expired. Please try again.' );
        return;
    }

    if ( ! get_option( 'users_can_register' ) ) {
        $wpide_register_errors = new WP_Error( 'closed', 'Registration is currently closed.' );
        return;
    }

    $login = isset( $_POST['wpide_user_login'] ) ? sanitize_user( wp_unslash( $_POST['wpide_user_login'] ) ) : '';
    $email = isset( $_POST['wpide_user_email'] ) ? sanitize_email( wp_unslash( $_POST['wpide_user_email'] ) ) : '';
    $result = register_new_user( $login, $email );

    if ( is_wp_error( $result ) ) {
        $wpide_register_errors = $result;
        return;
    }

    wp_safe_redirect( add_query_arg( 'registered', 1, remove_query_arg( 'registered' ) ) );
    exit;
} );

add_shortcode( 'wpide_register', function () use ( &$wpide_register_errors ) {
    if ( is_user_logged_in() ) {
        return '<p class="wpide-register-note">You already have an account.</p>';
    }

    if ( ! get_option( 'users_can_register' ) ) {
        return '<p class="wpide-register-note">Registration is currently closed.</p>';
    }

    if ( isset( $_GET['registered'] ) ) {
        return '<p class="wpide-register-success" role="status">Thanks for signing up! Check your email for a link to set your password.</p>';
    }

    $login = isset( $_POST['wpide_user_login'] ) ? sanitize_user( wp_unslash( $_POST['wpide_user_login'] ) ) : '';
    $email = isset( $_POST['wpide_user_email'] ) ? sanitize_email( wp_unslash( $_POST['wpide_user_email'] ) ) : '';

    ob_start();

    if ( is_wp_error( $wpide_register_errors ) ) {
        echo '<div class="wpide-register-errors" role="alert">';
        foreach ( $wpide_register_errors->get_error_messages() as $message ) {
            echo '<p>' . wp_kses( $message, array( 'strong' => array() ) ) . '</p>';
        }
        echo '</div>';
    }
    ?>
    <form class="wpide-register-form" method="post">
        <p><label for="wpide-user-login">Username</label><br>
        <input type="text" id="wpide-user-login" name="wpide_user_login" value="<?php echo esc_attr( $login ); ?>" autocomplete="username" required></p>
        <p><label for="wpide-user-email">Email</label><br>
        <input type="email" id="wpide-user-email" name="wpide_user_email" value="<?php echo esc_attr( $email ); ?>" autocomplete="email" required></p>
        <?php do_action( 'register_form' ); ?>
        <?php wp_nonce_field( 'wpide_register', 'wpide_register_nonce' ); ?>
        <p><button type="submit">Create account</button></p>
    </form>
    <?php
    return ob_get_clean();
} );
```

## Notes

"Anyone can register" must be enabled in Settings > General. Other registration snippets (invite codes, account types, verification) also apply because it uses the core registration function.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Front-End Registration Form Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
