为什么我的if语句默认为else选项 - Wordpress [英] Why is my if statement defaulting to the else option - Wordpress

查看:273
本文介绍了为什么我的if语句默认为else选项 - Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

if (is_page('541')){
    function __my_registration_redirect(){
        return home_url( '/affiliates-access/' );
    }
    add_filter( 'registration_redirect', '__my_registration_redirect' );

}else if(is_page('1119')){
    function __my_registration_redirect(){
        return home_url( '/equinox-apartments/' );
    }
    add_filter( 'registration_redirect', '__my_registration_redirect' );
}else{
    function __my_registration_redirect(){
        return home_url( '/' );
    }
    add_filter( 'registration_redirect', '__my_registration_redirect' );
}

它假设检测表单提交的页面并重新指向相应的不同页面,但总是去 else 声明....为什么?我无法解决这个问题。看起来它应该有意义

its suppose to detect the page that the form is submitted on and redirrect to a different page accordingly, but is always going to the else statement.... why? I cannot work it out. It seems like it should make sence

推荐答案

应该是这样的:

function __my_registration_redirect() {

    if ( is_page('541') )  return home_url( '/affiliates-access/' );
    else if ( is_page('1119') ) return home_url( '/equinox-apartments/' );
    else return home_url( '/' );

}
add_filter( 'registration_redirect', '__my_registration_redirect' );

这篇关于为什么我的if语句默认为else选项 - Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆