有条件重定向WordPress,如果引用网址不匹配



如果页码匹配,我尝试添加条件登录,并且wp_get_referer匹配$value执行操作,但我不知道我卡了一些

add_action( 'template_redirect', 'wpse15677455_redirect' );
function wpse15677455_redirect() {
$ref = wp_get_referer();
$value = ('https://mywebsite.com/quotaton/') ;
if (!is_page(555)) & $ref => $value {
wp_redirect( home_url() ); 
// exit; //( I also dont know if need exit if i add this code in function)
}
};

我也认为这是我不知道的解决方案是对还是不对

add_action( 'template_redirect', 'wpse15677455_redirect' );
function wpse156774_redirect() {
$ref = wp_get_referer();
if (is_page(555)) &&  if (strpos($ref, 'quotaton') !== false) {
echo 'true';
}
};

提前致谢

在我了解条件后,我想出了解决方案:

add_action( 'template_redirect', 'wpse1567745555_redirect' );  
function wpse1567745555_redirect() {
$ref = wp_get_referer();
if (is_page(227) && $ref == "https://mywebsite/quotaton/") {
//echo 'Its Working Let it Continue';
}
else if (is_page(227) && $ref !== "https://mywebsite/quotaton/"){
wp_redirect( 'https://mywebsite/sorry/', 301 ); exit;
// Not Working Let's Redirect and exit 
}
else if (!is_page(227)){
// echo 'Its Not Need Anything Here';
}
}

上面的代码对于WordPress很有用,如果您只想允许用户访问来自某个URL的某个页面。

如果有任何建议,请添加它们。

你的问题我不清楚。但我想你正在寻找这个。

add_action( 'template_redirect', 'wpse15677455_redirect' );
function wpse15677455_redirect() {
$value = ('https://mywebsite.com/quotaton/') ;
if (!is_page(555) & wp_get_referer() !== $value ) {
wp_safe_redirect( get_home_url() );
}
};

最新更新