This is quite a nice trick if you don’t like buttons such as Facebook Like or any Twitter counter buttons on your WordPress website or blog. With this method, you can display your Twitter count as normal text and it can blend in quite nicely if you have custom WordPress theme for your blog or website.

Create a new file and call it twittercounter.php and paste the below code into that file.  Make sure the file is located in the root of your theme file.

{code type=PHP}

<?php
$tw = get_option(“twitterfollowerscount”);
if ($tw[‘lastcheck’] < ( mktime() – 3600 ) )
{
$xml=file_get_contents(‘http://twitter.com/users/show.xml?screen_name=antonrsa’);
if (preg_match(‘/followers_count>(.*)</’,$xml,$match)!=0) {
$tw[‘count’] = $match[1];
}
$tw[‘lastcheck’] = mktime();
update_option(“twitterfollowerscount”,$tw);
}
echo $tw[‘count’];
?>

{/code}

Make sure to replace antonrsa with your twitter name.

Then Simply place this code anywhere you want to display your Twitter counter:

{code type=PHP}

<?php include(“twittercounter.php”); ?>

{/code}

Blog post Re Tweets

If you would like to display your blog post re tweets without a plugin, use the code below on your blog post pages.  Usually you can paste it in the file single.php located in the root of your theme files.

{code type=PHP}

<?php

$link = get_permalink($post->ID);
$key = ‘Backtype Key’;

$url = “http://api.backtype.com/tweetcount.xml?q=$link&amp;key=$key”;
$request = new WP_Http;
$result = $request->request( $url );

echo “<span class=\”result\”>”.$result[‘body’].”</span> tweets”;

?>

{/code}

Replace the $key = ‘Backtype Key’ with your own key on Backtype.

Book Your FREE Consultation

Take the first step to double your leads and sales. Schedule your complimentary 30-minute consultation now.

     

     

     

     

     

     

    There’s no commitment, just FREE, personalised, actionable strategies to build your business online!

    Free GA4 Ecommerce Marketing Dashboard

    Start measuring the ROI of your online store with the FREE Google Analytics 4 Ecommerce Marketing Dashboard template.

       

       

       

       

       

       

      You will be emailed a link to the report.

      Pin It on Pinterest