Create shortcode to display admins first & last name

I want to display the site admins first & last name on a page for all viewers & logged in users alike.

I have the following shortcode that I got help with so I can display the admins name in my header.php template.
Would it be easy to update the following code that displays the info I need correctly so I could have a shortcode that could be used on my pages as well? Something like [admins_first_last]?


function z_show_current_name(){
	// Get the current admin user, using it's registered email as key
	$user_info = get_user_by( 'email', get_option('admin_email'));
	// Use the user_info found to distill the info wanted
	$user_fname = $user_info->first_name;
	$user_lname = $user_info->last_name;
	$text = 'TESTING: ';
	// Return the output to show
	return '<span class="lmn_user_info lmn_user_fname">' . $user_fname . '</span><span class="lmn_user_lname"> ' . $user_lname . '</span>';
  • Michelle Shull
    • DEV MAN’s Apprentice

    Hey, George!

    Sure thing! We just need to add a tiny bit of code after the closing curly brace ( } ) and before the closing PHP tag ( ?> ) in your existing code, like so:

    add_shortcode( 'admins_first_last', 'z_show_current_name' );

    Then you can use [admins_first_last] as a shortcode in any post, page or widget, as long as your theme supports it.

    Take care!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.