0

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.

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();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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