Displaying the Total Number of Twitter Followers as Text on WordPress
Yes it is great that you can have a twitter follower button from many sites. But what if you are trying to make a very custom design where you want to place a code in text instead of using a button. Well then this tutorial is for you. In this tutorial we will show you how you can display the total number of twitter followers as text on your WordPress site.
Create a new file called twitter.php file located in your themes folder. Remember to make sure that you change WPBeginner to your username.
<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() – 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?>
Then simply paste this code any where you want in your theme files.
<?php include("twitter.php"); ?>
Now you can display the number of twitter followers on your WordPress site as text.
Source: WPRecipes
Comments
8 Responses to “Displaying the Total Number of Twitter Followers as Text on WordPress”Share Your Opinions
Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!
Please make sure that you have read our Comment Policy.








Great simple tutorial,
Really useful.. thanks man !
When I try to use this, I get the following error:
Fatal error: Maximum execution time of 30 seconds exceeded
any idea what could be the issue?
I too have gotten the same error, and upon receiving the timeout error it also stops loading the remainder of my site (i.e. sidbar, follow on posts past the first one).
Also, thanks for keeping this site going it been such a big help.
Try the new code.
Where exactly do I put this?
won’t find it! i placed it on the theme folder and usng and on the actual themes folder and it can’t find it
It is suppose to go in your actual themes folder.
nice tutorial.. i will try in my web