mikeoberdick

Create a WordPress Welcome Message for Users

Feb 6th, 2016
1,637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. // Create a welcome message shortcode
  2. function d4tw_welcome_msg () {
  3. $current_user = wp_get_current_user(); //get the current user info
  4. if ( is_user_logged_in () && ( $current_user->user_firstname ) ) { //this will run if user is logged in and has a first name registered
  5. return '<p>Welcome back ' . $current_user->user_firstname . '. Thank you for shopping!'; //return the message
  6. }
  7. elseif ( is_user_logged_in () && ( ! $current_user->user_firstname ) ) { //this will run if user is logged in with no first name registered
  8. return '<p>Welcome back ' . $current_user->nickname . '. Thank you for shopping!'; //run the message
  9. }
  10. else {
  11. return 'Welcome, guest! Click <a href = "/my-account/">here</a> to create an account or login.'; //this will run for guest users
  12. }
  13. }
  14. add_shortcode('welcome_message', 'd4tw_welcome_msg');
Add Comment
Please, Sign In to add comment