[英]How to redirect user based on page?
I am trying to use below code that whenever user goes to page name called "Through Phone Call" it should direct him to certain page我正在尝试使用下面的代码,每当用户转到名为“通过电话”的页面名称时,它应该将他定向到某个页面
In functions.php在functions.php中
function my_custom_add_to_cart_redirect( $url ) {
$page_title = $post->post_title;
if ($page_title == "Through Phone Call") {
$url = get_permalink( 2855 );
} else {
$url = get_permalink( 1853 );
}
}
But the code is not functioning what i am missing?但是代码不起作用我缺少什么?
According to the docs you need to call wp_redirect()
like below:根据文档,您需要像下面这样调用
wp_redirect()
:
function my_custom_add_to_cart_redirect( $url ) {
$page_title = $post->post_title;
if ($page_title == "Through Phone Call") {
$url = get_permalink( 2855 );
} else {
$url = get_permalink( 1853 );
}
wp_redirect( $url );
exit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.