Last active
May 20, 2023 22:37
-
-
Save Acephalia/259dbfede7ef9e5d1012d0511151eb2a to your computer and use it in GitHub Desktop.
Wordpress Greet Logged In User Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wordpress Greet Logged In User Shortcode | |
function detective_otter_found_you( $atts ) { | |
global $current_user, $user_login; | |
get_currentuserinfo(); | |
if ($user_login) { | |
$display_name = '<a href="' . get_permalink( get_option('woocommerce_myaccount_page_id') ) . '">' . $current_user->display_name . '</a>'; | |
return 'Hi ' . $display_name . ','; //Change Hi to desired greeting. | |
} else { | |
return 'Hi <a href="' . get_permalink(get_option('woocommerce_myaccount_page_id')) . '">Guest</a>,';//Change Hi and guest to desired greeting. | |
} | |
} | |
add_shortcode( 'show_loggedin_as', 'detective_otter_found_you' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use shortcode [show_loggedin_as] anywhere to print Hi Person (Person = Users display name) | |
Name links to My Accoount Page | |
If user is not logged in the shortcode displays Hi Guest | |
Guest Links to My Account login page. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment