WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Getting Co-Authors Plus to work with Oxygen (13 posts)

  1. Passa
    Member
    Posted 1 year ago #

    I'm trying to implement Co-Authors Plus plugin into my website. What I'm having trouble with is editing my template to show the co-authors instead of the first author. The instructions unfortunately don't correlate to the theme I'm using.

    I'm new to WordPress (and web development in general) but it appears my template uses shortcodes for the author string in the index and post pages. I thought maybe I could get the multiple authors to show if I modified the shortcodes.php file inside my template. The short code it uses is called [entry-author] and this is the relating code:

    /**
         * Displays an individual post's author with a link to his or her archive.
         *
         * @since 0.7.0
         * @access public
         * @param array $attr
         * @return string
         */
    
        function hybrid_entry_author_shortcode( $attr ) {
            $attr = shortcode_atts( array( 'before' => '', 'after' => '' ), $attr );
            $author = '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( get_the_author_meta( 'display_name' ) ) . '">' . get_the_author_meta( 'display_name' ) . '</a></span>';
            return $attr['before'] . $author . $attr['after'];
        }

    I tried to change it myself by replacing "get_the_author_meta" with "get_the_coauthor_meta" but now it just says "by Array" on each post. If anyone could point me in the right direction and help me correctly modify my theme to support Co-Authors Plus, that would be brilliant.

    Thanks!

    http://wordpress.org/extend/plugins/co-authors-plus/

  2. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Still need help with this?

  3. Passa
    Member
    Posted 1 year ago #

    Yes, unfortunately. Haven't managed to solve the problem myself.

  4. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Can you try replacing your function with this snippet instead?

    function hybrid_entry_author_shortcode( $attr ) {
    	$attr = shortcode_atts( array( 'before' => '', 'after' => '' ), $attr );
    	if ( function_exists( 'coauthors_posts_links' ) ) {
    		$author = coauthors_posts_links( null, null, null, null, false );
    	} else {
    		$author = '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" title="' . esc_attr( get_the_author_meta( 'display_name' ) ) . '">' . get_the_author_meta( 'display_name' ) . '</a></span>';
    	}
    	return $attr['before'] . $author . $attr['after'];
    }
  5. Passa
    Member
    Posted 1 year ago #

    Wow, that worked perfectly. Thanks a lot! Both authors show up on the custom Oxygen front page as well as on the post itself.

    Much appreciated!

  6. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    My pleasure :)

  7. Mark
    Member
    Posted 1 year ago #

    I'm running into a similar issue with the custom_author_byline plugin.
    I can probably apply a similar fix, but I'm working with an Oxygen child theme and I don't like modifying core theme files. Is there a way to redefine this function, perhaps in functions.php?

  8. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Why not use the guest author bylines feature of Co-Authors Plus instead?

  9. Mark
    Member
    Posted 1 year ago #

    Thanks, I will investigate that option. (The main reason we went for the simpler Custom Author Byline plugin is that that quite a few authors on our website are one-offs and we don't necessarily want to go through the trouble of creating co-authors for them.)

    The problem then remains though: how would you use the fix you describe above in a child theme, without modifying any parent theme files? I've tried redeclaring the relevant functions and shortcodes in my child theme's functions.php, but I suspect I'm running into issues with the priorities and phases of adding actions and removing shortcodes. Getting out of my depth there.

    The best solution for broad compatibility would be if the Hybrid [entry-author] shortcode could be made to refer to a redefined or enhanced entry-author-shortcode function, but I'm still not sure how to accomplish that in a child theme.

  10. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    I'm not familiar with the theme, sorry. It would be worthwhile to reach out to the theme author. They might be willing to add theme support for Co-Authors Plus.

  11. Mark
    Member
    Posted 1 year ago #

    Sorry, I wasn't very clear. This is not just the Oxygen theme. Oxygen is one of many themes based on the Hybrid core by Justin Tadlock, a highly respected plugin author and theme developer.

    From the Co-Authors Plus page:

    And, if your theme is using the appropriate template tags, you can create guest bylines without any additional configuration.

    What are "the appropriate template tags"? If a theme uses get_the_author_meta( 'display_name' ) and get_author_posts_url( get_the_author_meta( 'ID' ), will it work? If not, could Co-Authors Plus be made to filter those functions too? Or do you think it is the theme's business to check for the presence of Co-Authors Plus?

  12. Mark
    Member
    Posted 1 year ago #

    By the way, Co-Authors Plus is fantastic. I've switched from Custom Author Byline and I'm not going back. The guest author bylines feature is very useful and using the above tweak I can get it to work with Hybrid-based themes.

    The problem still remains that one has to edit Hybrid core files to make it work, due (apparently) to the Co-Authors Plus filters not being applied to all author-related function calls. (See my question above about "appropriate template tags".)

  13. Daniel Bachhuber
    Hand Built
    Plugin Author

    Posted 1 year ago #

    Sorry for the late reply on this. For multiple bylines to be added to your posts, you'll need to use the get_coauthors*() template tags. get_the_author_meta() is only going to work for the first user assigned to the post, and won't work for guest authors.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic