0

I apologize if this is an easily answered question - I've been looking for a while and can't quite get my head around it.

I would like to modify the first label for the wp-login.php page based on the potential user. My current plan is to use url parameters to differentiate users, have a function that checks for a parameter then returns the appropriate label.

Currently, this function does successfully change the username field label:

add_filter(  'gettext', array($this, 'register_text' ) );
add_filter(  'ngettext', array($this, 'register_text')  );
public function register_text( $translating ) {
     $translated = str_ireplace(  'Username or Email Address',  'Warranty Registration Number',  $translating );
     return $translated;
}

But I am struggling to make this conditional. My last attempt looked like this:

public function register_text( $translating ) {
    $para_log = $_GET['param']
    $s14 = 's14'
    $p32 = 'p32'

            if ($para_log == $s14) {
                 $translated = str_ireplace(  'Username or Email Address',  'Dealer Number',  $translating );
             return $translated;

            } elseif ($para_log == $p32) {
                 $translated = str_ireplace(  'Username or Email Address',  'Distributor Number',  $translating );
            return $translated;

            } else {
                 $translated = str_ireplace(  'Username or Email Address',  'Registration Number',  $translating );
            return $translated;
            }
    endif;

}

But this crashes the page. I'm hoping I just suck and it's a syntax error I can't see.

I've also tried variations of this, but no luck here either:

   function login_function() {
add_filter( 'gettext', 'username_change', 20, 3 );
function username_change( $translated_text, $text, $domain ) 
{
    if ($text === 'Username') 
    {
        $translated_text = 'customLoginName';
    }
    return $translated_text;
}

add_action( 'login_head', 'login_function' );

Any help would be appreciated. Thanks.

0

It is some syntax errors. on line 2 to 4 you're missing ending semicolons.

And endif line is not needed for curly-braces if statement.

  • Thank you! With both of those syntax changes the code works perfectly. Thanks again. – Curtis B Feb 24 at 19:55
0

I think it's a syntax error: the endif; statement is to be used to close if() : statements, as not using curly braces cannot identify the limits of the blocks:

if($something):
  //code
endif;

When using "braces-styled" if-elses you have just to use curly braces:

if($something){
  //code
}else if($somethingElse){
  //more code
} else {
  //even more code
}
  • Thank you for explaining! You were right - endif; wasn't needed. I did need some semi colons to end lines 2-4 as the other commenter said as well. Thank you for taking the time. – Curtis B Feb 24 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.