How this is accomplished is conceptually simple, but code tweaks are required in several places to pull this off. The code that actually does the registration can redirect to anywhere once the registration is successful, provided nothing has yet been output and that the code knows where to go. This is done with wp_redirect()
.
One way for code to know where to redirect to is to include a hidden field in the form that contains the final destination. For this to happen, the code that creates the form’s hidden field needs to know what that destination is. This could be accomplished by having all links to the registration page include an URL parameter that has the current page URL. So the href in the registration link might look like this:
inhouserecruitment.com/register/?redirect=current-page-slug
The registration form code can then get the destination with $_GET['redirect']
and include that value in a hidden form field. If the form field’s name is also ‘redirect’, then the registration code can get the destination with $_POST['redirect']
for use in wp_redirect()
once the registration is successful.
You can see how the original page’s slug is passed along in each step so the correct redirect can occur. Simple enough, but getting this to happen by altering the existing code could be tricky. It depends on how the current code is implemented. One could certainly directly hack the code to meet our needs, but then our changes could be lost when the theme or plugin is updated. The challenge is to do this in a manner such that theme or plugin updates leave our code unchanged.