Skip to content

Instantly share code, notes, and snippets.

@aurooba
Last active August 26, 2016 02:03
Show Gist options
  • Save aurooba/933eb903603a08643f2a342dbec059d2 to your computer and use it in GitHub Desktop.
Save aurooba/933eb903603a08643f2a342dbec059d2 to your computer and use it in GitHub Desktop.
Making Co-author Plus play nice with Yoast SEO Open Graph
/**
* Pulls the correct facebook link for guest authors using
* Co-author Plus. Ideally, need to fix this so it works with empty fields as well.
*/
add_filter('wpseo_opengraph_author_facebook', 'aa_wpseo_facebook');
function aa_wpseo_facebook($fb) {
if(! function_exists('get_coauthors') )
return $fb;
$coauthors = get_coauthors($GLOBALS['post']->id);
if (!is_array( $coauthors ) || empty($coauthors))
return $fb;
foreach ( $coauthors as $coauthor ) {
if ( ! isset( $coauthor->facebook ) || empty( $coauthor->facebook ) ):
$default = 'http://facebook.com/[ADD YOUR DEFAULT FB PAGE HERE]';
return $default;
endif;
return $coauthor->facebook;
}
return $fb;
}
/**
* Pulls the correct twitter link for guest authors using
* Co-author Plus. Ideally, need to fix this so it works with empty fields as well.
*/
add_filter('wpseo_twitter_creator_account', 'aa_wpseo_twitter');
function aa_wpseo_twitter($twitter) {
if(! function_exists('get_coauthors') )
return $twitter;
$coauthors = get_coauthors($GLOBALS['post']->id);
if (!is_array( $coauthors ) || empty($coauthors))
return $twitter;
foreach ( $coauthors as $coauthor ) {
if ( ! isset( $coauthor->twitter ) || empty( $coauthor->twitter ) ):
$default = '[ADD DEFAULT TWITTER HANDLE HERE]';
return $default;
endif;
return $coauthor->twitter;
}
return $twitter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment