Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active May 20, 2023 22:37
Show Gist options
  • Save Acephalia/259dbfede7ef9e5d1012d0511151eb2a to your computer and use it in GitHub Desktop.
Save Acephalia/259dbfede7ef9e5d1012d0511151eb2a to your computer and use it in GitHub Desktop.
Wordpress Greet Logged In User Shortcode
// 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' );
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