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 badge1 Answer
Reset to default 1Yes, 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
版权声明:本文标题:redirect - Page access only from a specific page in wordpress website 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741943471a2406279.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论