WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I building a site in WordPress (my own theme) that includes a very simple "sign up" email form. Person enters name and email address and hits submit button. Client currently using a script through Bluehost so I want to recreate vs. using a form plugin.

The form is fine. After hitting "submit" person is redirected to a "Thank You" page. I would like to be able to add a "back to page" link after the "Thank You for signing up" message that would take them back to whatever page they were on (the form will be on most site pages).

Tried adding this to the template:

$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "<a href='$url'>Back to Page</a>";

but it generates an error message because it's kicking back to Bluehost, not to the original page.

Can anyone help?


share|improve this question
up vote 1 down vote accepted

There's a great function called wp_redirect(), unfortunately not supporting "last page" argument yet, but I hope it will soon.

I believe the easiest (but not the most elegant way) way to achieve what you need is by using JavaScript, in jQuery it will look like:

<script type="text/javascript">
   jQuery(document).ready(function() {
      jQuery('#back-link').click(function() {
<a href="#" id="back-link">Go back</a>

It won't refresh the last page though, but in my opinion it's even better.

Hope it helps.

share|improve this answer
Thank You Wordpressor: this is what I needed! Appreciate the help! – PVA Nov 22 '11 at 17:56
@PVA, welcome on board. – Wordpressor Nov 23 '11 at 2:03

Use a JavaScript history trick for the back button.

<a href="#" onClick="history.back();return false;">Back to Page</a>

Here's a complete discussion why you have to use a JavaScript redirect: http://stackoverflow.com/questions/8046859/how-to-trigger-browsers-back-event-function-using-javascript

Hope it helps!

share|improve this answer
Thank You Rutwick, that was helpful! – PVA Nov 22 '11 at 17:56
You're welcome! – Rutwick Gangurde Nov 23 '11 at 2:56

Your Answer


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.