WordPress check if the user is logged in

<?php
if ( is_user_logged_in() ) {       
$current_user = wp_get_current_user();
printf( 'Hola %s!', esc_html( $current_user->user_firstname ) );  }
?>