integrating some of the suggested functions into your code:
<?php
$c_user = wp_get_current_user();
if( !is_user_logged_in( $c_user->ID ) ) :
echo '<a href="' . esc_url( wp_login_url() ) . '" alt="' . esc_attr( 'Login', 'textdomain' ) . '">';
echo _e( 'Login', 'textdomain' );
echo '</a>';
wp_register("https://wordpress.stackexchange.com/", '');
else :
echo 'Hello ' . $c_user->display_name . ', ';
echo ' <a href="' . esc_url( wp_logout_url( home_url() ) ) . '" alt="' . esc_attr( 'Logout', 'textdomain' ) . '">';
echo _e( 'Logout', 'textdomain' );
echo '</a>';
endif;
?>
some remarks:
-
for the ‘Register’ link to show, you need to have ticked in the dashboard:
‘Settings’ – ‘General’ – ‘Membership [ ] Anyone can register -
the ‘Logout’ will redirect to the home page; if you don’t want that, remove
home_url()
from the code