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

How to redirect to new page after download file has initiated? WordPress


I run a site which gives away psd graphics as freebies. After the visitor has clicked the download link I want the page to redirect to a "thank you for downloading" page.

I now this is not a straight up WordPress inquiry but still, can anyone help me with this?

Orman over at uses a method that seems cool.

Answers (7)


John Cotton answers:

PremiumPixels is using this javascript to do it:

jQuery(function () {

// get the GET variables
var theme = getUrlVars();

var downloadLink = '' + theme['file'] + '.zip';

jQuery('#downloadLink').attr('href', downloadLink);


function delayedDownload()
timeoutID = window.setTimeout(downloadTheme, 1000);

function downloadTheme()

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

for(var i = 0; i < hashes.length; i++)
hash = hashes[i].split('=');
vars[hash[0]] = hash[1];

return vars;


So his link to the file is actually a link to another page with a query string variable (in this case, the name of the download file without .zip on it.


What you are seeing is the contents of /download - try without the ?file=menu on the end....!

So the user clicks through to the next page (which could be anything of course - you could easily have some logic in there that detected the actual file being downloaded and change the contents of the page based on that) and then the script above fires off, reads the query string and downloads the file!

LeTune comments:

Hi John, could you help me implement this?

Send an email to [email protected]


Gabriel Reguly answers:

Hi LeTune,

Use a meta tag.

<meta http-equiv="refresh" content="5; url=">


-- Edit: John Cotton gave a good answer, here is the link to the jQuery code [[LINK href=""]][[/LINK]]

Maybe this code is not GPL, you should check it before using the code.


Ali Hussain answers:

Do you use any plugin or is it that you place a download link directly?


Julio Potier answers:


What kind of code are you using for the download link ?
Ajax mode ? or "just" click-to-get mode ?

See you soon


Ryan Riatno answers:

You can use plugin to do that here's some:

There's option to redirect to a new page after user click download


Hai Bui answers: use javascript/jQuery to do it. I can create the same function for you, but it only works if you insert the download links manually. PM me if you are interested.

LeTune comments:

Hi Hai,
I add download links via custom field, manually for every post. Send me an email at [email protected]


Arnav Joy answers:

Try to run the code of downloading in the thanks page itself.
I have done it something similar in
if it is uerfull to you then you can contact me at
[email protected]