This article was originally published in January 2011.
I rewrote the article in November 2012 to take advantage of new features developed since then.
David Gray wrote a follow-up article in September 2014 which you might also want to review.
If you have a magazine-like website, you might need to specify multiple authors for a single post. There’s a great plugin called Co-Authors Plus that will let you do this.
Once installed, you can use many template tags, or you can use the get_coauthors() function to retrieve all the author data and use it however you like.
Authors Shortcode
The Post Info area of Genesis can be customized using a filter. We could drop the coauthors_posts_links() function in there to list authors and link to their archive pages, but it would be even better to create a shortcode to be used in the post info section. If that function isn’t available (ex: someone disabled the plugin), it will use the standard get_author_posts_url() instead.
We will create a shortcode called [post_authors_post_link] with the following parameters:
- between – what to display between authors, default is a comma
- between_last – what to display between the last two authors, default is “and”
- before – what to display before the list of authors, default is empty
- after – what to display after the list of authors, default is empty
To set up the shortcode, add the following to your functions.php file or core functionality plugin:
| /** | |
| * Post Authors Post Link Shortcode | |
| * | |
| * @author Bill Erickson | |
| * @link http://www.billerickson.net/wordpress-post-multiple-authors/ | |
| * | |
| * @param array $atts | |
| * @return string $authors | |
| */ | |
| function be_post_authors_post_link_shortcode( $atts ) { | |
| $atts = shortcode_atts( array( | |
| 'between' => null, | |
| 'between_last' => null, | |
| 'before' => null, | |
| 'after' => null | |
| ), $atts ); | |
| $authors = function_exists( 'coauthors_posts_links' ) ? coauthors_posts_links( $atts['between'], $atts['between_last'], $atts['before'], $atts['after'], false ) : $atts['before'] . get_author_posts_url() . $atts['after']; | |
| return $authors; | |
| } | |
| add_shortcode( 'post_authors_post_link', 'be_post_authors_post_link_shortcode' ); |
Now if we want to update the Genesis Post Info to display all post authors (with “by” right before the listing), we’d add this to functions.php:
| /** | |
| * List Authors in Genesis Post Info | |
| * | |
| * @author Bill Erickson | |
| * @link http://www.billerickson.net/wordpress-post-multiple-authors/ | |
| * | |
| * @param string $info | |
| * @return string $info | |
| */ | |
| function be_post_info( $info ) { | |
| $info = '[post_authors_post_link before="by "]'; | |
| return $info; | |
| } | |
| add_filter( 'genesis_post_info', 'be_post_info' ); |
Author Boxes
Genesis also has a feature called the Author Box that displays the author information at the bottom of the post. But this doesn’t use Co-Authors Plus, so if you have multiple authors only one will show up at the bottom.
First we’ll remove the Genesis Author Box. Then we’ll copy the code into our own function, but this one will accept an author ID field so we can render any author with it. Finally, we’ll create a function that checks to see if Co-Authors Plus is in use, and if it is, display author boxes for all authors; if it isn’t, display the author box for the normal post author.
| // Remove Genesis Author Box and load our own | |
| remove_action( 'genesis_after_post', 'genesis_do_author_box_single' ); | |
| add_action( 'genesis_after_post', 'be_author_box' ); | |
| /** | |
| * Load Author Boxes | |
| * | |
| * @author Bill Erickson | |
| * @link http://www.billerickson.net/wordpress-post-multiple-authors/ | |
| */ | |
| function be_author_box() { | |
| if( !is_single() ) | |
| return; | |
| if( function_exists( 'get_coauthors' ) ) { | |
| $authors = get_coauthors(); | |
| foreach( $authors as $author ) | |
| be_do_author_box( $author->data->ID ); | |
| } else { | |
| be_do_author_box( get_the_author_ID() ); | |
| } | |
| } | |
| /** | |
| * Display Author Box | |
| * Modified from Genesis to use an ID | |
| * | |
| * @author Bill Erickson | |
| * @link http://www.billerickson.net/wordpress-post-multiple-authors/ | |
| */ | |
| function be_do_author_box( $id = false ) { | |
| if( ! $id ) | |
| return; | |
| $authordata = get_userdata( $id ); | |
| $gravatar_size = apply_filters( 'genesis_author_box_gravatar_size', 70, $context ); | |
| $gravatar = get_avatar( get_the_author_meta( 'email', $id ), $gravatar_size ); | |
| $title = apply_filters( 'genesis_author_box_title', sprintf( '<strong>%s %s</strong>', __( 'About', 'genesis' ), get_the_author_meta( 'display_name', $id ) ), $context ); | |
| $description = wpautop( get_the_author_meta( 'description', $id ) ); | |
| /** The author box markup, contextual */ | |
| $pattern = $context == 'single' ? '<div class="author-box"><div>%s %s<br />%s</div></div><!-- end .authorbox-->' : '<div class="author-box">%s<h1>%s</h1><div>%s</div></div><!-- end .authorbox-->'; | |
| echo apply_filters( 'genesis_author_box', sprintf( $pattern, $gravatar, $title, $description ), $context, $pattern, $gravatar, $title, $description ); | |
| } |
Joshua says
Bill,
How would I do this for my Thesis theme with this plugin? Is it pretty similar? I’m hoping to have the multiple authors show up in the fashion of “Author 1, Author 2 and Author 3” or “Author 1 and Author 2” but I’ll settle for “Author 1, Author 2, Author 3”. I just want to make sure I can have all applicable authors show up in the headline.
Thanks,
Joshua
Bill Erickson says
Instead of using a filter on genesis_post_info, you could write a function and hook it into thesis_hook_byline_item. Be sure to remove the Author from the byline in Thesis Options first.
For example (untested code):
Al says
Hi Bill,
thank you for this appreciated tutorial.
I would display, with coauthor plus plugin, also the list of (both) authors and co-authors in a sidebar, but all my attemps haven’t success. Could you kindly tell me where is the bug?
I’ve insert in functions.php of my theme
function get_coauthor_list() {
global $wpdb;
$authors = implode("','",get_terms('author',array('fields'=>'names')));
$sql = "SELECT ID " .
"FROM {$wpdb->users} " .
"WHERE user_login IN ('{$authors}') " .
"ORDER BY display_name";
return $wpdb->get_col($sql);
}
and in the sidebar.php file
<div class="author" id="author-">
<a href="">
but the result is a display of some co-authors and not other authors!
Do you know a different solution for achieve the target of a complete author/coauthor list?
Thank you,
Al
Bill Erickson says
I’m sorry, but this is beyond the scope of my post. I recommend you try the coauthors plus support forum: http://wordpress.org/tags/co-authors-plus?forum_id=10
Al says
sorry,
the complete second code is this, below:
<div class="author" id="author-">
<a href="">
Al says
ok, thanks anyway
Tony Escobar says
Hey Bill, thanks for the great tutorial. I really appreciate it.
Do you have a tutorial or know of any resources that would help me include the secondary authors bio after the post? Basically, display two author bios on a single post (using the Co-Authors Plus plugin and the tutorial you provided above). Thanks!
Bill Erickson says
You’ll need to rebuild the author box function. Use the example code in the first code snippet, but instead of just returning the author name, use the code from Genesis’ author box to display all their information.
Wes Linda says
Tried adding the code to my site, and it appears to not be loading. Using the education theme. Here is a page where there are two authors noted in Co Authors Plus.
http://www.hopkinsarthritis.org/arthritis-info/rheumatoid-arthritis/ra-symptoms/
Bill Erickson says
The issue is that you’re using it on a page, not a post. You can update the code in my snippet to use is_page() instead of is_single()
Steffen says
Hi Bill!
I have a problem with the post info area. I have included the code in my funtions.php file but instead of the author names i see the code “[post_authors_posts_link before=”by “]” in frontend view. Multiple Author boxes works fine.
I am using the fashionista genesis theme.
Thanks.
Steffen
Bill Erickson says
Sorry, there was a typo in that code snippet. It should be [post_authors_post_link] (no ‘s’ on post).
Nick Ciske says
Bill, thanks for sharing this — it’s exactly what I needed for a project.
I ran into an issue with the second author box not being displayed because CoAuthors Plus was returning the guest author post type for that user vs. the WP User Object (while it returned the WP User for the Main Author).
Here’s how I fixed it to handle both cases:
https://gist.github.com/4428434
Bill Erickson says
Thanks! I haven’t used the guest author feature so didn’t know it returned something different.
TJ Greene says
Bill,
I found this page while researching how to replicate some of your handiwork over on Yoast’s site. Specifically, customizing the post info function to go from Genesis’ default of ‘January 8, 2013 by Author’s Name’ to ‘By Author’s Name – Last update October 27th, 2012’ whenever a post is modified. Kudos, it’s BRILLIANT! Just what I’m looking for. I don’t suppose you have a tutorial on it anywhere, or know where I can find some helpful info?
Anyway, my problem is unrelated to this post, however, I wanted to let you know that your link above to Studiopress’s post on customizing post info (http://dev.studiopress.com/customize-post-info.htm) is broken. That info would be really helpful as I start digging deeper into Genesis. I love their stuff, but it can be confusing to the inexperienced.
Best Regards,
TJ Greene
Bill Erickson says
I’ve updated the link to point to the new page on their site.
To display the post info as you’re requesting, try this: https://gist.github.com/4556324
TJ Greene says
Bill,
Thanks for updating the link above, and, especially, for taking the time to share the code for modifying the post info the way I needed. It was a big help and worked perfectly!
Best Regards,
TJ Greene