I need to display the username of the main site administrator for a part of my template.
I have used the following short code to display the email address of the main administrator of the site with which he started WordPress:
<?php bloginfo('admin_email'); ?>
But I did not find any short code to display the username of the main administrator of the site.
Is there such a shortcode or should I get the username of the main administrator of the site in another way?
2
Answers
There is not a shortcode that I know of, but writing one is very simple, and a great exercise to learn shortcode creation:
Simply add that code to your themes functions.php file and use the shortcode
[admin_email]
where you want the email address to be displayed.As a bonus, here’s another shortcode for you that would generate a list of all site Admins if there was more than one:
To get the FIRST administrators email address:
if you want to get the user for the email that the admin set during setup you can do so by combining
bloginfo('admin_email')
andget_user_by()
functions.Something similar to:
Take into account that once you get the WP_User object ($admin_user) you can retrieve any value from the
wp_users
table (see here).