我有多个联系形式在我的wordpress网站,并有一个不同的感谢页面为每一个。因此,我想通过输入urls来阻止直接访问感谢页面。我想,如果用户填写了表单,而不是重定向到该表单,谢谢页面。
我有1感谢页面的工作代码,但我不知道如何设置多个联系人表单&谢谢页面。
// ID of the thank you page
if ( ! is_page(1911)) {
return;
}
// coming from the form, so all is fine
if (wp_get_referer() == 'https://www.example.com/contact') {
return;
}
// we are on thank you page
// visitor is not coming from form
// so redirect to home
wp_redirect( get_home_url() );
exit;
} );```
Other thankyou page id's: 1269, 1825, 1623
Other contact form page urls: https://www.example.com/contact-form-2, https://www.example.com/contact-form-3, https://www.example.com/contact-form-3发布于 2020-05-20 06:26:30
我自己解决了这个问题。我在这里张贴解决方案,以防有人遇到同样的问题。
function wpse15677455_redirect() {
$ref = wp_get_referer();
if (is_page(1911) && $ref !== "https://www.example.com/contact"){
wp_redirect( get_home_url() );
}
else if(is_page(1269) && $ref !== "https://www.example.com/contact-form-2"){
wp_redirect( get_home_url() );
}
else if(is_page(1825) && $ref !== "https://www.example.com/contact-form-3"){
wp_redirect( get_home_url() );
}
else if(is_page(1623) && $ref !== "https://www.example.com/contact-form-4"){
wp_redirect( get_home_url() ); exit();
};https://wordpress.stackexchange.com/questions/364320
复制相似问题