How to Display Twitter Counter in WordPress blog
Astra WordPress Theme

How to Display Twitter Counter in WordPress blog

Today I will show you how to How to Display Twitter Counter in WordPress blog similar as RSS counter post, you can display it anywhere you want in your WordPress blog. You can style it and make it more beautiful.

Create a new text file and save it in php format and name it twitter and then paste the following code in the file and save it. So it will be twitter.php

Don’t forget to Photoshop Tutorial : Create a Simple Gaming Layout

Subscribe to Email Newsletter, Photoshop Tutorial : Create a Simple Gaming Layout Follow us on Twitter and Photoshop Tutorial : Create a Simple Gaming Layout Like us on Facebook – for recent updates.

<?php
//Your Twitter XML Link
$turl="http://twitter.com/users/show.xml?screen_name=YOUR TWITTER USERNAME";

//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Set the URL
curl_setopt($ch, CURLOPT_URL, $turl);

//Execute the fetch
$data = curl_exec($ch);

//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$tw = $xml->followers_count;
//end get cool feedburner count

echo $tw;

?>

After pasting these lines to your file we have to add Twitter user name, so replace the YOUR TWITTER USERNAME with your Twitter user name on the following line

$turl="http://twitter.com/users/show.xml?screen_name=YOUR TWITTER USERNAME";

Then sim­ply add this line of code wher­ever you want the counter to dis­play:

$turl="http://twitter.com/users/show.xml?screen_name=YOUR TWITTER USERNAME";

Save your twitter.php file to your theme files where you have hosted the blog.

Written by
AsHok Jain
Join the discussion

Let’s get social

Web design blog for professionals with topics focusing on useful design techniques, design best practices and design inspiration. Subscribe for updates!

15585

JOIN OUR GROWING LIST OF SUBSCRIBERS!

Following our blog is a great way to make sure that you are up to date on the latest and greatest Freebies and WordPress news.

15856