There are several reasons why you’d want to show author information blocks on your site. It could be either because you have multiple authors, or you allow for guest posts on your blog. One of the reasons why people would want to guest post is because they can gain some extra exposure.
A cool way of doing this is using the built-in author functions with some extra’s to add a “Guest post by” block to your template. I’ve done this on yoast.com, and you can find an example here.
How I did this? Using Gravatars and the new author_meta functrions in WordPress of course!
WordPress has added template tags you can use to show author info and Gravatars, so it’s pretty easy. So you can just add the following code to your theme. I’ve annotated all lines, you should be able to copy paste and modify:
<?php
// If it's not written by me (username admin), it's a guest post,
// hence check for that:
if (get_the_author_meta('user_login') != "admin") {
// If it's a guest post, show the appropriate block
?>
<div class="guestauthor" id="
<?php the_author_meta('user_email'); ?>">
<?php
// Make sure the image is right aligned
function avatar_align($avatar) {
return str_replace("class='","class='alignright ",$avatar);
}
add_filter('get_avatar','avatar_align',10,1);
echo get_avatar( get_the_author_meta('ID'), '60' );
// Show the author's information
?>
<h3>Guest post by: <?php the_author_meta('display_name'); ?></h3>
<p><?php the_author_meta('description'); ?></p>
</div>
<?php
}
?>
The last thing is that, in order for HTML to be allowed in user profiles, you need to add the following line to your themes functions.php:
// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');
That’s it! You now have cool “Guest post by” blocks on your site!




Thanks, Joost! I can think of several sites this functionality will be perfect for
Does this require wp 2.8? Will it work on WPMU 2.7?
It requires 2.8, yes.
This is great. I do lots of sites for churches and this would be great to add for speakers to go with podcast episodes. Thanks.
Cool, let us know how it works out!
JUST what I was needing – thanks!
is there an example of this code in use?
Joost –
I see the second block of code goes in the funtions file. Where do you put this first block of code? In the header.php file?
Hi Joost,
Could you please answer Stephanie’s question about where to place the first block of code. It is a excellent question that you didn’t answer in the post. I would like to use your tip and need to know where to place it.
Thanks so much in advance, Jocelyn
Can this code be set up so non-guest would include other users as well as admin?
For example, a site is set up so “authors” would be “guest bloggers”, and all other users
except subscribers would be staff bloggers for the site?
I think it’s not only cool for guest-posters, but also for the core team of a website. I assume the user information is loaded from the WordPress Profile (more in particular from the “Biographical Info” text).
Where does the top code go? Since Joost isnt answering, does anyone else know?
This would go in the index.php files of StudioPress themes or possibly single.php files of themes that don’t have a home.php file.
Thanks for this cool trick but as a very new user I am just learning how to style my themes.
I found the index.php on my lifestyle theme, but between what and what should I paste this? I don’t want to mess up the theme!
Thanks
this not working for me