How To Pull & Publish User Information For An Author Bio Section in WordPress
You know, there really is a lot to be said for WordPress. Not only is PHP – the language WordPress is based on – very versatile and easy to learn, but WordPress comes with so many built-in functions that you can really customize an amazing site.
For those of you who have followed my past articles, you will know that I cover WordPress fairly often. In fact, there are a few of us here at MUO that regularly lift the hood to do some tweaking. James has produced a lot of WordPress tutorials lately.
While it’s true that most people will simply install a theme and only customize the WordPress site to the extent allowed by the control panel, the truth is that with just a little bit of study and practice, you can easily tweak the PHP files within any WordPress template to customize it for your needs.
Customizing Your WordPress Site With User Information
The closest thing I’ve come to this is when I wrote about how to add a dynamic author footer to your WordPress blog posts. In my opinion, that is really a feature that every blog should have – it provides for a much more professional appearance, and it offers more credibility to the reader.
If you read that article, you’ll see that I used several built-in functions that are part of WordPress, including one that obtains the name, email address, number of posts, profile picture and author description from the profile page. You can take all of that data and then string it together into text that dynamically gets published depending on what article is currently on the page and who the author is.
I was really excited when I discovered how to do that, but more recently I came across a situation where the method above didn’t work – a central page, like the website main blog page, where there is no single “author” for the page. In that case, the method above won’t work. If you use the functions I listed in that article, it will always pull the default author.
This makes it really hard when you want to build an box of author bios for all of the writers on your site. I also noticed that there are very few blogs out there that have published how to do this – everyone is writing about the standard “the_author()” functions that look at the author for the current page.
Before you get started using the functions that I’m going to introduce you to, first go to your “Edit User” page in WordPress, and for each of your users, you’ll need to know the email address they’ve signed up with, as well as the User_ID. You can see this when you go to edit their profile, as it’s listed in the URL next to “user_id=“.
Once you have those two pieces of information from the user profile, you’re ready to get started with the “get_userdata” function. Here is a simple script that will extract both the avatar photo and the user_description from the WordPress user profile.
<span style="float:left;margin:0 10px 0 0;"> <?php $author_email = "firstname.lastname@example.org"; echo get_avatar($author_email, '80')?></span> <?php $user_info = get_userdata(4); echo $user_info->user_description . "\n"; ?>
How does this work? It’s pretty simple. The “get_avatar” is not dependent upon the current author of the page, it only cares about the e-mail address to obtain the avatar. But to get the description text, you have no choice but to use “get_userdata()” to pull that information. The only parameter you have to send it is the “user_id” that you just wrote down. Here’s how it looks:
The secret here is that the “get_userdata()” function actually pulls a whole list of parameters that you can obtain. Above, I only did an “echo” of the user_description text from the user profile, but you could also have the script print out the user’s name, email address, their URL/blog, and even an array of what their WordPress editing permissions are.
The coolest thing about using this function rather than the “the_author()” set of functions is that with just the User ID, you can extract information about any single one of your registered users, regardless who authored the page where your script is running. This is ideal for a list of author bios for a website. For example, I placed all of the bios in the sidebar on my site and formatted it all to pull the author descriptions one after the other.
The beauty of this solution is that if you need to make any changes to the WordPress author bios, you don’t have to edit any of the pages. Just go to the profile page and edit the bio there, all content will instantly reflect those changes.
Do you have a WordPress site with multiple writers? Can you think of other creative ways to integrate user information into web page content? Share your own experiences and insight in the comments section below.
Image credit: Henk L
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.