0

I'm very new in wordpress, and I have a client that needs a custom registration/login form on the front-end side. I also need custom user fields. (phone, company name, about, blog url, etc).

For the custom fields I found the add_user_meta function on Wordpress Codex, but I didn't find any information about the custom registration/login page templates.

I finished my first Wordpress template, so I have idea how does it work, but I don't know where to start this registration/login thing.

p.s. I would like to do this without plugins.

1 Answer 1

1

WordPress has no default form or way to create custom registration and login pages. However, it is quite possible to do all this yourself! I'll try to get you started:

1. Page Templates

WordPress offers something called Page Templates. You can add a file (e.g. tpl-my-template.php to your theme and add

/*
Template Name: My Template
*/

at the start of the file. Now, when you create a page in the admin panel, the "Page Attributes" box on the right allows you to select this template. When a page with "My Template" as the template is displayed, it will use the file tpl-my-template.php.

You could create page templates for the login page and for the registration page, so you can add your forms and custom logic to the page via the page templates.

2. Adding the form

Next, you can add the registration form (or login form) with any fields you like. For security, you should add a hidden nonce field to this form.

3. Handling the form

WordPress is event-driven. It allows you to "hook into" actions and filters. You should do the same when checking your form. Try hooking into the init action, which is basically fired after most basic setup is completed but no output has been generated yet.

add_action( 'init', 'wpse152106_handle_registration' );

function wpse152106_handle_registration() {
    // Handle registration form
}

3.a Registration

To add a new user to an installation, you can use wp_insert_user, combined with add_user_meta for your custom fields.

3.b Logging in

You can log in using wp_signon, which also does error checking for you, returning a WP_Error object on failure.

I hope I've given you a few waypoints in tackling this problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.