Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a welcome message shortcode
- function d4tw_welcome_msg () {
- $current_user = wp_get_current_user(); //get the current user info
- if ( is_user_logged_in () && ( $current_user->user_firstname ) ) { //this will run if user is logged in and has a first name registered
- return '<p>Welcome back ' . $current_user->user_firstname . '. Thank you for shopping!'; //return the message
- }
- elseif ( is_user_logged_in () && ( ! $current_user->user_firstname ) ) { //this will run if user is logged in with no first name registered
- return '<p>Welcome back ' . $current_user->nickname . '. Thank you for shopping!'; //run the message
- }
- else {
- return 'Welcome, guest! Click <a href = "/my-account/">here</a> to create an account or login.'; //this will run for guest users
- }
- }
- add_shortcode('welcome_message', 'd4tw_welcome_msg');
Add Comment
Please, Sign In to add comment