I wanted to have a page on my site say something like “Mike Haydon currently has xyz number of followers on Twitter” as a social proof that I have some idea when it comes to social media.
The xyz needed to be regularly updated to reflect the current number. I figured php would be my best option. However, as Twitter is known to frequently go down, I didn’t want it to pull completely live data. Also, if the page gets lots of traffic, an additional php call would needlessly slow down the page.
The best way to overcome this problem is to cache the result and have a backup in case a scheduled check doesn’t pull a result (due to twitter being down or too many API calls). In case you don’t know, caching in this instance would fetch the follower count and store it for easy access until it was fetched again. Each time the page was accessed, it would display that stored result.
Sure enough, there’s a WordPress plugin that can do this and display it as inline text. It’s Followers Count, available at https://wordpress.org/plugins/social-media-followers-counter/
To use it, you’ll need to be able to execute php in the page (which doesn’t happen naturally). Just install Exec PHP: http://wordpress.org/extend/plugins/exec-php/
Once you’ve installed the two plugins and checked your settings, go to the Page or Post and put
<?php followers_count( ‘mikehaydon’, 70000 ); ?>
where you want the followers count to display, changing mikehaydon to your username and 70000 to the number of followers you want displayed when it fails to fetch the followers count.
In my example, I put:
He currently has <?php followers_count( ‘mikehaydon’, 70000 ); ?> followers on Twitter…
You can see it in action here: http://www.seoperth.net.au/social-media/
*Note: to use Exec PHP, you need to put the php code in the html editor and not view the editing area of that post with the visual editor again. Just make sure you finish the post before you put the code in and don’t go back to it later.