Show a total share counter (FB, Twitter, G+) WordPress Snoppet


SUBMITTED BY: Guest

DATE: Dec. 26, 2013, 6:27 a.m.

FORMAT: PHP

SIZE: 653 Bytes

HITS: 766

  1. Want to display how many times your post has been shared on Facebook, Twitter and Google+? This is what the snippet below will do for you. Paste it where you want the count to be displayed, within the loop.
  2. function social_shares() {
  3. $url = get_permalink( $post_id );
  4. $json = file_get_contents("http://api.sharedcount.com/?url=" .
  5. rawurlencode($url));
  6. $counts = json_decode($json, true);
  7. $totalcounts= $counts["Twitter"] +
  8. $counts["Facebook"]["total_count"] +
  9. $counts["GooglePlusOne"];
  10. echo "<div>$totalcounts Share</div>";
  11. }

comments powered by Disqus