duan19740319 2016-03-09 14:54
浏览 43
已采纳

关于if和else if语句的functions.php中的Wordpress PHP问题

My Home page is a static custom Login Page for a network multisite with the Theme-my-login plugin running om a Divi child theme. On the login page there is the login itself which works fine, and below that two "action links" for "Register" and "Lost Password". I have two custom pages to link to for both links.

So I edit the child theme's functions.php file. Let’s say you wanted to change the default Register action link to a different URL:

function tml_action_url( $url, $action, $instance ) {
    if ( 'register' == $action )
        $url = 'YOUR REGISTRATION URL HERE';
    return $url;
}
add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );

That works perfectly. If I want to include the lost password link too however:

function tml_action_url( $url, $action, $instance ) {
    if ( 'register' == $action )
        $url = 'YOUR REGISTRATION URL HERE';
    else if ( 'lost password' == $action )
        $url = 'YOUR LOST PASSWORD URL HERE';
    return $url;
}
add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );

it breaks for some reason. Any help much appreciated. I have a feeling I'm not using the correct syntax or something. TIA. Jim

  • 写回答

1条回答 默认 最新

  • dousou1878 2016-03-09 15:02
    关注

    From documentation

    Note that elseif and else if will only be considered exactly the same when using curly brackets. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

    Either use elseif instead of else if or use curly brackets like so:

    function tml_action_url( $url, $action, $instance ) 
    {
        if ( 'register' == $action )
        {
            $url = 'YOUR REGISTRATION URL HERE';
        }
        else if ( 'lost password' == $action )
        {
            $url = 'YOUR LOST PASSWORD URL HERE';'
        }
        return $url;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双非跨考工科哪个专业和方向就业前景好?
  • ¥20 求会6sv辐射传输模型,辅导(可py6s🙏🏻有偿
  • ¥15 .xla后缀的文件拖到excel里什么内容也没有怎么办
  • ¥20 Workbench中Mechanical打不开、闪退是什么原因?
  • ¥240 MapReduce应用实践 学生课程
  • ¥15 hlss视频显示AUTHORITY_INVALID
  • ¥15 MAX9296A+MAX96717,美信gmsl解串有人做过吗?
  • ¥15 求帮我解决一下inode 爆满的问题(有偿)
  • ¥15 关于#vscode#的问题:布料滤波算法中C++实现pcl在Vscode中pcl库没有#include <pcl>
  • ¥15 fpga:ov5640采集tft显示