David Stockdale's Scrapcode

Embed Customisation Supporting “Co-Authors Plus”: Final Solution

So a while ago while doing some volunteer work I fiddled around with making the website adding support for “Co-Authors Plus” in embedded posts as outlined in Embed Customisation Supporting “Co-Authors Plus”.

 I found that my solutions all looked rather messy.

I presented those initial attempts to my boss and after making a few changes based on his feedback this is what we eventually settled on.

/**
 * Removes the title (David Stockdale).
 */
add_filter('embed_site_title_html','__return_false');
/**
 * Adds the author's names (David Stockdale).
 */
add_action( 'embed_content', 'embed_author' );
/**
 * Adds the author div to the embed iframe (David Stockdale).
 */
function embed_author() {
	$output = '<div class="wp-embed-author">By:';
	$coauthors = get_coauthors();
	$loopcheck = 0;
	foreach( $coauthors as $coauthor ): 
		/**
		 * Checking if it's the first line to decide if it should be seperated with a comma.
		 */
		if($loopcheck == 0) {
			$loopcheck++;
		} else {
			$output .= ',';
		}
		$output .= ' ';
		$authorArchiveLink = get_author_posts_url($coauthor->ID);
		$output .=  "<a href=$authorArchiveLink> $coauthor->user_firstname $coauthor->user_lastname</a>";
	endforeach;
	$output .= '.';
	$output .= '</div>';
    echo $output;
}

By removing the author portraits I was able to create a cleaner looking list.

I then styled it to fit the websites theme of links in a specific colour.

/**
 * Customises the style/colours of embedded posts.
 */
add_action( 'embed_head', 'embed_styles' );
/**
 * Embed the plugin's custom styles.
 */
function embed_styles() {
    echo <<<CSS
<style>
	.wp-embed-author {
		margin-top: 0.5em;
	}
	.wp-embed-author a {
		color: #a6191a;
	}
	.wp-embed-author a:hover {
		color: #454545;
	}
</style>
CSS;
}

All in all a much neater look that is far more consistant with the website as a whole.

Leave a Reply