Below is the copy-and-paste code snippet as mentioned in the above video:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* This shortcode [get-user-first-name] will display the logged in Users first name only. */ add_shortcode( 'get-user-first-name' , 'get_user_first_name' ); function get_user_first_name() { $current_user = wp_get_current_user(); $first_name = $current_user ->user_firstname; $last_name = $current_user ->user_lastname ; return $first_name ; } /* This shortcode [greet_user] will display the word Welcome followed by the logged in Users first name. */ add_shortcode( 'greet_user' , 'greet_user' ); function greet_user() { $current_user = wp_get_current_user(); $first_name = $current_user ->user_firstname; $last_name = $current_user ->user_lastname ; return "Welcome, $first_name" ; } |