We create beautiful & user-friendly websites and provide quality web development services worldwide.
Contact us to get started on your project.


How to Display Total Number of Social Shares for Each WordPress Post

Published by Veron Ang | 2


For blogs that see high traffic and engagement, what is the best way to showcase this activity to your users? One popular way is to display the total number of comments for each post.

Another way is through social proof, by showing the number of times each post has been shared. Mashable does it for all their stories, and boy do they have many Facebook and Twitter shares. Not only is this a great way to “show off” your site’s engagement, it’s also useful for your readers to be able to tell at one glance which of your posts are the most popular.

We can do the same thing as Mashable by leveraging on SharedCount’s technology, which counts the number of times a URL has been posted/shared/liked on Facebook, Twitter and Google Plus.

Display Total Number of Facebook, Twitter and Google Plus Shares

To do this, simply add the following function to your theme functions.php file, after the opening <?php tag.

function sparklette_social_shares() {
    $url = get_permalink( $post_id ); 
    $json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));
    $counts = json_decode($json, true);
    $totalcounts= $counts["Twitter"] + $counts["Facebook"]["total_count"] + $counts["GooglePlusOne"];
    echo $totalcounts . " shares";

Then call the function wherever you would like to display the number, for instance, in The Loop or the single.php file, like this:

<?php sparklette_social_shares(); ?>

About the Author

Veron Ang is a , developer and WordPress expert at Sparklette Studio. She graduated with a bachelor's degree in computer science from the National University of Singapore. Engage her to work on your next project by sending her a message from the contact page or on Twitter.


  • really awesome tutorial.
    I like very much your tutorial.

  • Yeah Greaat!!!! thanks :D

Leave a comment