Display User Login Status

Show a custom message based on the user’s login status.

<?php
function display_user_login_status() {
    if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        echo '<p>Welcome back, ' . esc_html($current_user->display_name) . '!</p>';
    } else {
        echo '<p><a href="' . wp_login_url() . '">Login</a> to access more features.</p>';
    }
}
add_action('wp_footer', 'display_user_login_status');

Post Comment