Wordpress PHP problem in functions.php regarding if statement and else if
My home page is a static custom login page for a layered network with the Theme-my-login plugin working with the Divi child theme. The login page has the login itself, which works great, and below these two "action links" for "Register" and "Forgot password". I have two custom pages to link to both links.
So, I am editing the functions.php file of the child theme. Let's say you wanted to change the link for the default action 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 );
This works great. If I also want to add a link to the lost password:
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 down for some reason. Any help is greatly appreciated. I have a feeling that I am not using the correct syntax or anything. TIA. Jim
source to share
From the documentation
Note that elseif and else if will be considered exactly the same when using curly braces. When using colon to define your if / elseif conditions, you must not separate the else if by two words, or PHP will fail with a parse error.
Use curly braces elseif
instead else if
or use curly braces, for example:
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;
}
source to share