0

I'm trying to create a generic, re-usable function that shows the site name on the login screen. It works with just static text, but how do I pull in the site name dynamically? Here's what I've tried:

function custom_login_message() {
    $message = '<p class="natz-login">Log in to <?php echo get_option( 'name' ); ?> </p><br />';
    return $message;
    }
    add_filter('login_message', 'custom_login_message');

This is obviously wrong, but what do is use instead of <?php echo get_option( 'name' ); ?> ?

2 Answers 2

0

The function you are looking for is get_bloginfo().

function wpse407167_custom_login_message( $message ) {

    $message = '<p class="natz-login">Log in to ' . get_bloginfo('name') . '</p><br>';
    return $message;
    
}
add_filter( 'login_message', 'wpse407167_custom_login_message', 99 );
3
  • Sadly not. This is giving me a critical error if added to my functions file. Jun 29, 2022 at 13:14
  • @ChanningKrendler Sorry, my bad. There was a syntax error on my code. Fixed it. Try now and let me know.
    – Abhik
    Jun 29, 2022 at 17:09
  • Flipping brilliant. That's exactly it!! Thanks, @Abhik. Jun 30, 2022 at 13:29
-1

if you mean, the php to replace <?php echo get_option( 'name' ); ?>
then it's probably <?= bloginfo('name') ?>

1
  • You mean <?php bloginfo('name') ?> I guess? No. Unfortunately, that's also coming with a site-wide critical error. Jun 29, 2022 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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