Skip to content

How to add the number of Twitter followers into your site?

The first thing to do is to paste the following php functions on the functions.php file from your WordPress blog theme:

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("".$username);
  $doc = new DomDocument;
  $ele = $doc->getElementById('follower_count');
  return $innerHTML;

Then, simply paste the following anywhere on your theme files. Just replace my username with yours.

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

If you enjoyed this article, please consider sharing it!

Published inCodingWordpress

One Comment

  1. Bulk SMS Reseller

    Thanks for sharing your twitter tip. It really helps a lot in my case since I’m newbies on the road.

Leave a Reply

Your email address will not be published. Required fields are marked *