How do I display "Hello username" if logged-in on the homepage

I am trying to show the name of the currently logged-in user in a small text like 'Hello, username!'.

I tried to do this, but it doesn't work:

p class=vam
    ?php if(is_user_logged_in()):
    $current_user = wp_get_current_user(); ?
        Hello, b?php echo $current_user-display_name; ?/b!
    ?php else:?
        Hello, spanClient/span!`

Topic username shortcode Wordpress

Category Web


try my variant:

<?php if (!is_user_logged_in()) : ?>
    <form action="<?=get_home_url(); ?>myaccount" method="POST">                                            
        <input type="submit" value="<?php _e('Hello, Client! Click to sign in:', 'theme'); ?>">                     
    </form>
<?php  else:  ?>
    <a href="<?=get_home_url();?>myaccount"><?php _e('Hello ', 'theme'); echo wp_get_current_user()->user_login;?></a>
    <a href="<?=wp_logout_url(esc_url( 'https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ));?>myaccount">Logout</a>
<?php  endif; ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.