Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to redirect a user who logs in using wp_login_form to a custom page that is created automatically on signup

It seems like the URL needs to be absolute and obviously the end of the URL would change with each user.

Please see the function used to create the page on signup

function create_user_page($user_id) {
    if ( $user = get_userdata($user_id) ) {
        // Create a new user-specific page
        $page = array(
                'comment_status' => 'closed',
                'ping_status' => 'closed',
                'post_name' => $user->user_login,
                'post_status' => 'publish',
                'post_title' => $user->user_login,
                'post_type' => 'page'
            );

So, when a user logs in via the page that includes wp_login_form they need to be redirected to http://www.websiteurl.com/user1 etc. where user1 is the page that has been created.

I hope that made sense.

share|improve this question

1 Answer 1

Yeah its pretty simple! I believe you already have the code to create a page in place. Like if we are using wp_insert_post() it will return the post ID on success. So you can do something like this:

$page_id = wp_insert_post( $args );
wp_redirect( get_permalink( $page_id ) );
die();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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