0

I have a page template, which redirects to the homepage using this:

wp_redirect( home_url() );

Now, on the homepage is it possible to check if it has been redirected from a specific page template without knowing the URL of that page?

0

You can use the $_SERVER['HTTP_REFERER'] to check the page where it redirected from

You can use it as below.

if($_SERVER['HTTP_REFERER'] == "path-of-page-you-want-to-check"){
//Do something here
}

Conditionally you can call functions like is_home(), is_front_page() to run that block of code in homepage only

| improve this answer | |
  • Just a tip on your formatting, don't add function names or short pieces of code in bold, use backticks or codeblock. Also, your method is not really reliable, although it will work in most cases, check this post for a workaround :-) – Pieter Goosen Dec 16 '14 at 11:47
  • My pleasure. Quick is not always preferable, reliable is. Always good to know alternatives :-). Enjoy – Pieter Goosen Dec 16 '14 at 12:31

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.