Site logo

Archived topic

Integrating Co-Authors Plus

9 replies · Started by Marcel on February 13, 2020

Viewing posts 1–10 of 10

So do I add this to functions.php?

add_filter( 'generate_post_author_output', function( $author ) {
    if ( function_exists( 'coauthors_posts_links' ) ) {
        return sprintf( ' <span class="byline">%1$s</span>',
            coauthors_posts_links( null, null, null, null, false )
        );
    }

    return $author;
} );

Hi Leo,

I can see that the authors changed on the Search Results pages. For example: https://entrepreneurcaribbean.com/?s=leadership

But it didn't change it in an element I'm using. I'm using this in an element: <span id="ph-author">{{post_author}}</span><span id="ph-date">{{post_date}}</span>

Do I need to change that as well?

Hi David, thanks for pointing that out.

But I tried these three lines of code but none of them work:

<span id="ph-author">[author_plus]</span><span id="ph-date">{{post_date}}</span>
<span id="ph-author">{{author_plus}}</span><span id="ph-date">{{post_date}}</span>
<span id="ph-author">{{[author_plus]}}</span><span id="ph-date">{{post_date}}</span>

Am I doing something terribly wrong?

You need to add this to Theme:

add_shortcode( 'author_plus', 'tu_coauthors_plus_shortcode' );
function tu_coauthors_plus_shortcode() {
	return sprintf( ' <span class="byline">%1$s</span>',
		function_exists( 'coauthors_posts_links' ) ? coauthors_posts_links( null, null, null, null, false ) : ''
	);
}

Using one of the methods here:
https://docs.generatepress.com/article/adding-php/

Then add this to your Header Element:

<span id="ph-author">[author_plus]</span><span id="ph-date">{{post_date}}</span>

Awesome! It works! Thank you so much for all your help!

Glad we could all be of help

This archived topic is closed to new replies.