Count the Number of Shares to Facebook, Twitter, LinkedIn & Google Plus

I’ve recently consolidated two websites into one as a means of managing my time and resources more effectively. The other sites will be revived in one way or another but they’ll be built ‘low maintenance’. Apart from the multiple site to manage, there was a large overlap in content that was far too difficult to ignore.

Related post: “Display Total Number of Social Shares with PHP and WordPress Shortcode”.

In the process of moving posts across I couldn’t work out an effective manner in which to retain Facebook shares, Twitter counts and so on. Instead of implementing a solution that would have been rather server intensive, I decided to simply retrieve the post count from a few networks and display that (aggregated) information under each post.

This post details how to retrieve post counts from the big four social networks and – if you’re interested enough – how to render that data on your screen in a small text box. I’ve posted about Twitter counts before in isolation; this post expands upon the same theme.

The Naked Functions

Get Number of Tweets from Twitter

Usage: echo get_tweets("");

Get Number of LinkedIn Shares

Usage: echo internoetics_get_shares("");

Get Number of Facebook Shares

Usage: echo internoetics_get_likes("");

Get Number of Google+1’s

Usage: echo internoetics_get_plusones("");

Shortcode Functions

The previous version of this post (we updated it in March, 2015) had a single function that aggregated all platforms – not pretty. Here’s individual shortcode functions.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.


Usage of [internoetics_twitter_shares url=""] returns (API no longer available)


Usage of [internoetics_linkedin_shares url=""] returns 12


Usage of [internoetics_facebook_shares url=""] returns 0

Google Plus One

Usage of [internoetics_plusone_shares url=""] returns 16

Update: If you’re after the number of shares rather than +1’s (e.g. for this post, rather than 16), see this post.


Changes don’t occur that often, and social networks aren’t necessarily quick to aggregate your new data. For that reason, it’s best to cache data for at least an hour. This prevents you making repeated and unnecessary requests to the various APIs.

Displaying Your Shares Like Mashable …

A common question in the comments and emails relates to how total shares can be displayed similar to Mashable. If you’re after an easier half-way WordPress solution, see this post.

Mashable Style Share Count

The Mashable Total Share Count

This is an image of the aggregated share count we played with (before we updated the website).

Total Share Count

Example Solution to a Mashable Style Share Count

We’ve got our own service in Beta. Like our Facebook page and you’ll be the first to get an invitation.

Download the Code

You can download the code here .

Shortt URL for this post:


  1. Ryan

    This is a great article! thank you! Just wondering how i would go about using the shortcode to pull in the count per post that is shared. I am using the short code like so in the loop for posts:

    but I am not getting anything back.

  2. Jason


    Thanks for the great article! I’m using it on my WP website.

    But by the Google+ counts I’m getting this error:
    Fatal error: Call to undefined function curl_init()

    I’m using WP 3.4.

    Can you please help?


  3. Matt

    Is there a way to add all the shares? So instead of having each separate, it would list the total? Something like how Mashable does it, I think.

    • Marty

      Sure. What I’ve provided above is grossly inefficient… to the point of negligence. I’ve got a database that stores the results of shares etc every few hours. Using my method it’s simply an issue of retrieving the shares attached to each post ID. I’ll try and find the time to post something soon.

      Using the above dodgy method, you can simply use addition to tally the total results. It’ll work, but it’s not best practice.

      It might be best if I email you an example.

  4. Daniel

    Thanks for your post.
    And now I found that… facebook functions should be changed for proper working like below.

    function get_likes($url) {
    $json_string = file_get_contents(‘’ . rawurlencode($url));
    $json = json_decode($json_string, true);
    return intval( $json[0][‘like_count’] );

  5. Alex

    I know we can get data about multiple urls with one request via facebook api. Can we do the same with twitter?

    Thank you in advance.

  6. sanjiv

    Hi Marty… the information you have shared is really very helpful.. I am a newbie in programming stuffs and already in some confusion after googling enough.. I have a website which hosts voting topics.. each voting topic has a fb like button.. I would like to get the facebook likes for each and every topic available in my website…. lets say I have urls like,, , etc etc.. I now want to get the likes for each of these urls in a single JSON file.. can you help me in this…I thank you in advance

  7. punit

    Is there any idea to count the no of email sent to friends. if you have please help me i am getting problem to count he number of email sent to anyone.

    • Marty

      I suspect the best option is to link a button through a counter of sorts and then just tally the number of ‘clicks’. There’s really no other way unless you want to use a third-part service that’ll just do as I’ve described. Do you want me to provide a sample?

  8. Pingback: Display a Mashable Style Total Number of Social Shares with PHP and WordPress Shortcode

  9. Rachel

    Hi, can you help me get the shares count only for the last 7 days? What should I add to the code above (the one in the beginning of this article)? Thank you!

  10. Pingback: Create Blockquotes with WordPress Shortcode | Internoetics

  11. Lee

    This gets the +1 count for google+, but what about the share count? I believe this is a distinct stat; is there a way to get it?

  12. Pingback: Count Google Shares for a URL with PHP | Internoetics

  13. wonderer

    hey, so I was hoping for something to aggregate all the shares of all my pages, i.e. total number of shares that ever been done for any url on facebook, or on twitter, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *