Multiple Authors for a Post

This article was originally published in January 2011.
I rewrote the article in November 2012 to take advantage of new features developed since then.

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:

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:

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.

chat24 Comments

  1. 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):

      add_action('thesis_hook_byline_item', 'multi_authors');
      function multi_authors() {
      $i = new CoAuthorsIterator();
      $return = '';
      $i->iterate();
      $return .= '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta('display_name').'</a>';
      while($i->iterate()){
      $return.= $i->is_last() ? ' and ' : ', ';
      $return .= '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta('display_name').'</a>';
      }
      echo $return;
      }
  2. 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

  3. 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.

    • 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()

  4. 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

  5. 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

  6. 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

  7. says

    Is this still working with an upgrade to Genesis 2.0? I have multiple authors in the post info but having trouble with the Author Box. Do I need to add the function to add the box before removing it? Not worry about that? I either have 1 box or none. Any help is appreciated. Thx!

  8. Lasse says

    Hi Bill,
    Thanks for all of your valuable wordpress tips!
    I am trying to implement your bit of code to enable co-authoring on my site. But whenever I try to alter the between_last value to something in my own language, I get the white screen of death. The reason might be that I am doing it wrong, so would you explaining in detail how to modify your bit of code?
    Many thanks,
    Lasse

Leave a Reply

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.