Last active
July 16, 2020 00:16
-
-
Save adriannees/fe78a1da106bf228b0b8a3850dcdc54e to your computer and use it in GitHub Desktop.
Add custom shortcode to output user name
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
| <?php | |
| // Refer: https://wordpress.stackexchange.com/questions/49686/how-do-i-display-logged-in-username-if-logged-in | |
| // Recommend adding as a code snippet using the code snippets plugin. Can also add to functions.php but will need to remember to transfer if change theme | |
| function mysite_custom_shortcode_makers() { | |
| if( is_user_logged_in() ) { | |
| $user = wp_get_current_user(); | |
| return '<h2>Hello ' . $user->first_name . ', welcome to your shop dashboard!</h2>'; | |
| } | |
| } | |
| add_shortcode( 'welcome_message', 'mysite_custom_shortcode_makers' ); | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need to tweak the template you can use
<?php echo do_shortcode( '[welcome_message]' ); ?>