How to Display Live Twitter Followers in WordPress (Expert Guide)

Having a large and growing Twitter following can be hugely beneficial for your WordPress site‘s success.

As a webmaster with over 15 years of experience, I‘ve seen firsthand how displaying your Twitter follower count publicly can help attract new readers and build authority.

In this comprehensive guide, I‘ll explain the top reasons to show your Twitter followers on your WordPress site. I‘ll also provide an in-depth look at the technical steps to display your live updated Twitter follower count using the Twitter API and custom PHP code.

Whether you have a personal blog or a business website, adding your real-time Twitter follower count can act as social proof and encourage more engagement. Let‘s get started!

4 Big Benefits of Displaying Your Twitter Followers

Before we dive into the technical details, let‘s look at some of the main reasons you should consider showing off your Twitter follower numbers:

1. Builds Trust and Credibility

High Twitter follower counts act as social proof that you have an established brand and audience. According to research by Mention, 72% of people are more likely to make a purchase decision after seeing a business profile with over 10K followers.

Visibly displaying your impressive Twitter follower count helps convince website visitors that your content is worth subscribing to. It shows you have influence in your niche.

2. Provides Social Proof That You‘re Worth Following

The Bandwagon Effect is the psychological principle that people are more likely to do something if they see others doing it too.

Showing a large Twitter following taps into this effect by encouraging new sign-ups. Even if visitors don‘t use Twitter themselves, a big follower count gives the impression that you‘re someone worth paying attention to online.

According to research by NY Mag, "When someone signs up for Twitter and follows popular or influential accounts, it increases the likelihood that they become more engaged with the platform."

3. Reflects Your Overall Social Media Influence

The number of followers you have on Twitter specifically showcases how influential you are on that social network. But it also acts as a proxy for your overall social media reach and authority.

Displaying an impressive count sends the message that you have established clout and reach on other platforms too. This strengthens your brand and influence both on and beyond Twitter.

4. Makes Email Outreach Easier

Doing cold email outreach is always difficult. But when the recipient can immediately see that you have an engaged audience, it demonstrates your influence.

This social proof that you have built a community around your work makes PR opportunities much more attainable. Influencers are far more likely to respond positively if they can verify your reach.

How Many Twitter Followers Is Good to Have?

How many followers should you have before displaying the count publicly? Here are some benchmarks:

  • 100+ – You have an established account worth paying attention to.
  • 500+ – You have a respectable following and are building influence.
  • 1000+ – You have broken into 4 digits and have a noticeable following.
  • 5000+ – You have a large following and impressive social clout.
  • 10,000+ – You have built a massive engaged audience and are a recognized authority.

Keep in mind these numbers can vary significantly based on your niche and industry. But in general, crossing 1000, 5000 and 10,000 followers are major milestones worth celebrating publicly.

Step-by-Step Guide to Display Twitter Followers in WordPress

Now let‘s dive into the step-by-step process for displaying your live Twitter follower count on a WordPress site.

There are 5 key steps we‘ll cover:

  1. Get a Twitter Developer Account
  2. Make an API Request for Follower Data
  3. Parse the Follower Count from the Response
  4. Cache the Result to Avoid API Limits
  5. Display with a WordPress Shortcode

Step 1: Get a Twitter Developer Account

In order to retrieve your Twitter follower data, you first need access to the Twitter API. This requires creating a Twitter developer account to get API credentials.

Here‘s how to get setup:

  1. Go to https://developer.twitter.com/ and click Apply for a Developer Account.
  2. Enter your name, email, phone, and how you intend to use the API.
  3. Review and agree to the Developer Agreement.
  4. Click Submit Application. Twitter will review it and email you if approved.
  5. Once approved, click your profile picture -> Developer Portal to access your dashboard.
  6. Go to Projects & Apps and click Create App. Enter a unique name and click Complete.
  7. You‘ll now see your Consumer API Keys with your API Key and API Secret.

Save your API Key and API Secret somewhere secure like a password manager. We‘ll need them to make API requests.

Step 2: Make an API Request for Follower Data

Now that you have API credentials, you can make requests to the Twitter API for data.

We‘ll use the GET users/show endpoint to retrieve your follower count.

This endpoint requires authentication using your API Key and Secret.

Here is sample PHP code to make the API request:

// Set your API credentials
$consumer_key = ‘YOUR-API-KEY‘; 
$consumer_secret = ‘YOUR-API-SECRET‘;

// Encode credentials for request authorization 
$credentials = base64_encode( $consumer_key . ‘:‘ . $consumer_secret );

// Set CURL options
$options = array(
    CURLOPT_HTTPHEADER => array(
        "Authorization: Basic {$credentials}",
        "Content-Type: application/x-www-form-urlencoded"
    )
);

// Make GET request to API endpoint
$url = ‘https://api.twitter.com/1.1/users/show.json?screen_name=yourusername‘;
$response = wp_remote_get( $url, $options );

This makes a request to the API using your authentication and returns the raw JSON response body.

Note: Replace "yourusername" with your actual Twitter username.

Step 3: Parse the Follower Count

Now that we have the raw JSON response, we need to parse it to extract just the follower count number.

Here is how to do this in PHP:

// Get response body
$body = wp_remote_retrieve_body( $response );

// Decode JSON 
$data = json_decode( $body );

// Get follower count
$follower_count = $data->followers_count;

The response JSON has a followers_count property containing the number we need.

Step 4: Cache the Result to Avoid API Limits

The Twitter API has rate limits on requests. So we should avoid hitting it on every page load.

The solution is to cache the follower count result using the WordPress Transients API. This stores data for a set time period before expiring.

Here is how to cache for 1 hour:

// Generate unique transient name 
$cache_key = ‘twitter_followers_‘ . $twitter_username;

// Get cached value if exists
$cached = get_transient( $cache_key );

// Update cache if empty or expired
if ( empty( $cached ) ) {

  // Make API request...

  // Cache for 1 hour
  set_transient( $cache_key, $follower_count, 1 * HOUR_IN_SECONDS ); 

} else {

  // Return cached value
  $follower_count = $cached;

}

Now the API is only hit when the transient cache expires, avoiding rate limits.

Step 5: Display with a WordPress Shortcode

To display your live Twitter follower count in WordPress, we can wrap the API logic into a shortcode.

Shortcodes allow outputting dynamic content using a simple tag like [myshortcode].

Here is an example shortcode:

// Display Twitter followers shortcode
function display_twitter_followers() {

  $count = get_twitter_followers(); // Defined previously

  return "<p>We have over <strong>$count</strong> Twitter followers!</p>";

}

add_shortcode( ‘my_twitter_followers‘, ‘display_twitter_followers‘ );

Now you can add the follower count anywhere on your site using:

[my_twitter_followers]

No need to hardcode the number! It will update automatically.

Alternative Display Options

Some other options for displaying your follower count include:

  • Widget – Make a custom widget to show in sidebars
  • Custom field – Save as post metadata and display in themes
  • Automatic hook – Hook into a theme file to add globally

Using a shortcode is the easiest way to get started. But widgets and hooks allow displaying the count even without shortcodes.

Top WordPress Plugins for Creating Shortcodes

If writing your own custom PHP shortcodes isn‘t for you, there are some great plugins that add shortcode functionality:

These plugins make it easy to create a shortcode without having to write your own definitions.

Troubleshooting: Common Issues Displaying Twitter Followers

Here are some common problems you may run into and how to fix them:

  • Wrong Count – Make sure your Twitter username is correct in the API request URL.

  • No Count – Double check your API key, secret, and authentication method.

  • Rate Limited – If you exceed the API rate limits, use caching to avoid too many requests.

  • Shortcode Not Working – Be sure to define and properly register the shortcode function.

  • Follower Count Stuck – Expire your transient cache if the count gets stuck and won‘t update.

  • CORS Error – Use a plugin to handle CORS issues when requests are made from the domain.

  • WP_Remote_Get Failing – Some hosts restrict remote calls, use a cURL request instead.

  • Authorization Error – Make sure your API keys are valid and you‘re encoding your credentials correctly.

Grow Your Influence with Twitter‘s Follower Count

Having a large, growing Twitter following is a sign of social media success. Displaying your follower count publicly can attract new followers and improve engagement.

In this guide, I covered the benefits of showing your Twitter followers, benchmarks for good follower counts, and a step-by-step implementation guide.

You now have everything you need to start displaying your live Twitter follower count on your WordPress site using the Twitter API and custom PHP code!

So put your Twitter following on show and watch your social proof and online influence grow.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.