Free Wordpress Blog Setup

Displaying the Total Number of Twitter Followers as Text on WordPress

By Editorial Staff in Tutorials
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

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

8 Responses to “Displaying the Total Number of Twitter Followers as Text on WordPress”
  1. Enk. says:

    Great simple tutorial,
    Really useful.. thanks man ! ;)

  2. :) this tut has been around awhile. another good one!

  3. FAQPAL says:

    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?

  4. Miki says:

    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

  5. denbagus says:

    nice tutorial.. i will try in my web

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.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting