admin管理员组

文章数量:1315294

I would like to know if it possible to have a page that open if and only if the visitor comes from a specific page (which in my case would be the homepage). So for example, the visitors land on the homepage, by clicking on a button the targeted page open. But if someone tries to visit the specific page without clicking on the button from the homepage, He would be redirected to another page : If visitor goes to Homepage and the visitor clicks button -> Specific page url opens If the visitor land on the specific page -> redirected to another page or the home page.

I am sorry if it is a bit confused, I hope you will be able to understand my question.

Thank you for your help. Peter

I would like to know if it possible to have a page that open if and only if the visitor comes from a specific page (which in my case would be the homepage). So for example, the visitors land on the homepage, by clicking on a button the targeted page open. But if someone tries to visit the specific page without clicking on the button from the homepage, He would be redirected to another page : If visitor goes to Homepage and the visitor clicks button -> Specific page url opens If the visitor land on the specific page -> redirected to another page or the home page.

I am sorry if it is a bit confused, I hope you will be able to understand my question.

Thank you for your help. Peter

Share Improve this question asked Dec 3, 2020 at 17:03 PeterPeter 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, it is possible by checking the referer on your target page before rendering the page. There may be a better way to solve your task, however, if you want to share more details. Setting a cookie, passing a parameter with the URL - there is usually more than one way to address a problem.

In answer to your question, wp_get_referer() will return the URL for the page the user arrived from or false if from the same page. https://developer.wordpress/reference/functions/wp_get_referer/

If your home page URL is 'http://mypage.local', this would work. Again, this is probably not the best approach for your project:

$referer = wp_get_referer();

if ( 'http://mypage.local' !== $referer ) {
  // User arrived from another source so send them away!
  wp_redirect( 'http://mypage.local/otherpage' );
  exit;
}

本文标签: redirectPage access only from a specific page in wordpress website