Skip to content

Instantly share code, notes, and snippets.

@ihorvorotnov
Last active October 28, 2017 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihorvorotnov/9132571 to your computer and use it in GitHub Desktop.
Save ihorvorotnov/9132571 to your computer and use it in GitHub Desktop.
WordPress - count shares via Sharedcount.com
/**
* http://www.sharedcount.com/documentation.php
*/
function social_shares() {
$url = get_permalink( $post_id );
$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));
$counts = json_decode($json, true);
$totalcounts= array(
"twitter" => $counts["Twitter"],
"facebook" => $counts["Facebook"]["total_count"],
"google" => $counts["GooglePlusOne"]
);
return $totalcounts;
}
/**
* instead of file_get_contents you can use wp_remote_retrieve_body
*/
$json = wp_remote_retrieve_body( wp_remote_get(‘http://api.sharedcount.com/?url=” . rawurlencode($url)));
@engagedcount
Copy link

SharedCount is no longer accepting new signups. We're providing an API compatible alternative at https://engagedcount.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment