When entering search keywords on a search form on 404 page, the search results are displayed on a new page with the URL like this: http://www.example.com/?s=xyz.

How can I find if this search result is queried from a 404 page and not from a blog page or a product page?


Easiest and most robust way is to add a url parameter to the search so the search url will be something like http://www.example.com/?s=xyz&from404=1. Probably easiest way to do that is by adding a hidden field to the form.

For "bonus points" use the browser's history API to remove the parameter after the page load.

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.