April 22, 2009

Display the total number of your Twitter followers on your WordPress blog

twitterI never thought about completely implementing a Twitter follower counter within your WordPress themes’ files, but Jean-Baptiste Jung. from WPRecipes.com has come up with an excellent way of achieving such a task.

Okay, so first off, copy and paste the following code, and add it to your current themes function.php file:

function string_getInsertedString($long_string,$short_string,$is_html=false){
  if($short_string>=strlen($long_string))return false;
  if($is_html && $inserted_string[$insertion_length-1]=='<‘){
  return $inserted_string;

function DOMElement_getOuterHTML($document,$element){
  return string_getInsertedString($html,$html2,true);

function getFollowers($username){
  $x = file_get_contents(“http://twitter.com/”.$username);
  $doc = new DomDocument;
  $ele = $doc->getElementById(‘follower_count’);
  return $innerHTML;

I think you know what’s coming next. Now, copy and paste the following WordPress code anywhere within your template and replace “kdogg290”, with your Twitter username.

<?php echo getFollowers("kdogg290")." followers"; ?>

Previous Post and Next Post

Try HostGator Webhosting for 1 cent for the 1st Month Click here and enter "wordpress"

Leave a reply

* means field is required.