Skip to content

Instantly share code, notes, and snippets.

@germanny
Last active July 4, 2017 03:52
Show Gist options
  • Save germanny/6222479 to your computer and use it in GitHub Desktop.
Save germanny/6222479 to your computer and use it in GitHub Desktop.
Google Plus stuff and PHP constants defined for Facebook Page ID, G+ Author Page, and Twitter Username from Yoast SEO plugin

Constants defined for Facebook Page ID, G+ Author Page, and Twitter Username

Using the Social fields in the SEO Plugin, we don't have to enter this data into the theme too:

/**
* Use Yoast SEO Plugin to create these constants
* http://wordpress.org/plugins/wordpress-seo/
* https://gist.github.com/germanny/6222479
*/
if ( function_exists( 'get_wpseo_options' ) ) {
   $get_options_wpseo_social = get_option('wpseo_social');
   define('TWITTER_USERNAME', $get_options_wpseo_social['twitter_site']);
   define('FB_PAGE', $get_options_wpseo_social['facebook_site']);

   $plus_author_link = get_user_meta($get_options_wpseo_social['plus-author'], 'googleplus', TRUE);
   $plus_author_link = ( substr($plus_author_link, -1) == '/' ) ? $plus_author_link . '?rel=author' : $plus_author_link . '/?rel=author';
   define('GOOGLE_PLUS_AUTHOR', $plus_author_link);

   $plus_publisher_link = $get_options_wpseo_social['plus-publisher'];
   $plus_publisher_link = ( substr($plus_publisher_link, -1) == '/' ) ? $plus_publisher_link . '?rel=publisher' : $plus_publisher_link . '/?rel=publisher';
   define('GOOGLE_PLUS_PUBLISHER', $plus_publisher_link);
} else {
   define('TWITTER_USERNAME', '');
   define('FB_PAGE', '');
   define('GOOGLE_PLUS_AUTHOR', '');
   define('GOOGLE_PLUS_PUBLISHER', '');
}

Google Plus links:

For proper G+ linking for Google searches, we need the following links in these places:

Author:

  • User profile = author's G+ link

SEO Plugin Social Tab:

  • Author for Homepage: Select blog author (with G+ link)
  • Google Publisher Page = OnlineMBA G+ Account link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment