Show all authors of Co-Authors Plus plugin

< 1 min read

Please add this code to file functions.php of your active theme:

// Content Views Pro - Show authors by Co-Authors Plus plugin
add_filter( 'pt_cv_field_meta_author_html', 'cvp_theme_field_meta_author_html_coauthor', 100, 2 );
function cvp_theme_field_meta_author_html_coauthor( $args, $post ) {

	// 1. To show author name and link
	if ( function_exists( 'coauthors_posts_links' ) ) {
		$args = coauthors_posts_links( null, null, null, null, false );
	}
	// end 1.

	// 2. To show author avatar and link
	if ( function_exists( 'get_coauthors' ) ) {
		$arr = array();
		foreach ( get_coauthors() as $coauthor ) {
			$avatar	 = get_avatar( $coauthor->user_email, '60' );
			$link	 = get_author_posts_url( $coauthor->ID, $coauthor->user_nicename );
			$arr[]	 = sprintf( '<a href="%s">%s</a>', esc_url( $link ), $avatar );
		}

		$args = $arr ? implode( '', $arr ) : $args;
	}
	// end 2.

	return $args;
}

Depending on your need, please remove the 1. or 2. block in above code.

Thank you,

Scroll to Top