Last active
December 22, 2022 05:28
-
-
Save elias1435/6b2f8f3bd233c73e15f7842a0537926d to your computer and use it in GitHub Desktop.
display current user name with shortcode. this code will go in functions.php
This file contains hidden or 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
function show_loggedin_function( $atts ) { | |
global $current_user, $user_login; | |
get_currentuserinfo(); | |
add_filter('widget_text', 'do_shortcode'); | |
if ($user_login) | |
return 'Welcome ' . $current_user->display_name . '!'; | |
else | |
return '<a href="' . wp_login_url() . ' ">Login</a>'; | |
} | |
add_shortcode( 'show_loggedin_as', 'show_loggedin_function' ); | |
//shortcode is [show_loggedin_as] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment