Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Redirect to last post visited after completion of a Gravity Form WordPress

  • SOLVED

I'm using Gravity forms for my user registration. When a user visits a post to go to single.php, they are prompted to either login or register. After completing their registration form (which is in the front end with gforms), I'd like them to be automatically redirected to the post they were trying to view.

*as a side note, if you're not familiar with gravity forms, they allow page redirects upon completion. let me know if you need admin access to further assess.

Answers (1)

2011-06-09

rilwis answers:

You can use this code (paste it into the functions.php file of your theme):

add_filter('gform_confirmation_YOURFORMID', 'rw_redirect', 10, 4);
function rw_redirect($confirmation, $form, $lead, $ajax) {
$referer = wp_get_referer();
$confirmation = array('redirect' => $referer);
return $confirmation;
}


You need to change YOURFORMID to your registration form ID.


rilwis comments:

I've just posted an answer but don't know why it doesn't appear. So I post it again.

You can use this code (paste into your functions.php file):

add_filter('gform_confirmation_YOURFORMID', 'rw_redirect', 10, 4);
function rw_redirect($confirmation, $form, $lead, $ajax){

$confirmation = array('redirect' => wp_get_referer());

return $confirmation;
}


Remember to change the YOURFORMID to your registration form ID.