Skip to content

Instantly share code, notes, and snippets.

@adriannees
Last active July 16, 2020 00:16
Show Gist options
  • Select an option

  • Save adriannees/fe78a1da106bf228b0b8a3850dcdc54e to your computer and use it in GitHub Desktop.

Select an option

Save adriannees/fe78a1da106bf228b0b8a3850dcdc54e to your computer and use it in GitHub Desktop.
Add custom shortcode to output user name
<?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' );
?>
@adriannees
Copy link
Copy Markdown
Author

If you need to tweak the template you can use <?php echo do_shortcode( '[welcome_message]' ); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment