displaying the total number of twitter followers as text on wordpress

## Displaying Your Twitter Followers Count as Text in WordPress: A Comprehensive Guide

**By Naveed Ahmed**

As a seasoned WordPress developer with over 15 years of experience, I’ve seen firsthand how crucial social proof is for boosting website credibility and trust. Displaying your Twitter followers count as text on your WordPress site is a simple yet powerful way to leverage that social proof, subtly demonstrating your influence and engaging your audience.

In this comprehensive guide, we’ll explore the benefits of displaying your Twitter follower count as text, walk through the step-by-step process, and address common questions. We’ll even delve into some advanced techniques for further enhancing your social media strategy.

**Why Display Your Twitter Follower Count as Text in WordPress?**

Let’s face it, we all instinctively trust what others recommend. When visitors see a large number of people following your Twitter account, it signals that your content is valuable and resonates with others. This social proof can:

* **Boost Website Credibility:** A high follower count instills confidence in your expertise, especially if your niche is specialized.
* **Increase Trust:** Visitors are more likely to trust a website with a strong social media presence, suggesting that others value the content and brand.
* **Drive Engagement:** The visibility of your follower count can encourage visitors to follow you on Twitter, expanding your reach and building a stronger community.

**Traditional Methods vs. Textual Display:**

While many social media plugins allow you to display follower counts within embedded feeds, buttons, or banners, using plain text offers several advantages:

* **Flexibility:** Textual display allows you to incorporate the follower count into any area of your website, including blog posts, page footers, or even within your website design.
* **Customization:** You have complete control over the presentation, allowing you to style it to match your brand and website design.
* **Emphasis:** By showcasing the count as plain text, you can draw attention to it and highlight its importance.

**Getting Started: A Step-by-Step Guide**

Here’s a detailed guide to displaying your Twitter follower count as text on your WordPress site:

**Step 1: Obtain Your Twitter API Key and Secret**

Before we begin, we need to access the Twitter API. Here’s how:

1. **Navigate to the Twitter Developers Portal:** Head over to [https://developer.twitter.com/](https://developer.twitter.com/) and click on ‘Sign up for Free Account’.
2. **Create a Developer Account:** Provide detailed information about your project and how you plan to use the Twitter API. Twitter may require a more detailed explanation for approval.
3. **Agree to the Terms and Conditions:** Carefully review the terms and click on the ‘Submit’ button.
4. **Access Your API Key and Secret:** Click on the ‘Projects & Apps’ section in the left-hand menu, then select ‘Overview.’ This will display your project app.
5. **Reveal Your Keys:** Click on the key icon to access your API Key and Secret, then click on the ‘Reveal API Key’ button.
6. **Store Your Keys Securely:** This is the only time you’ll see this information, so make a note of it somewhere safe. Consider using a password manager for added security.

**Step 2: Add Custom Code to Your WordPress Website**

Now, we’ll use PHP code to display the follower count. WordPress doesn’t allow direct PHP code insertion in posts and pages, so we’ll create a custom shortcode. The easiest way to manage this is with the free WPCode plugin:

1. **Install and Activate WPCode:** Download WPCode from the WordPress plugin repository and activate it on your site.
2. **Create a New Code Snippet:** Navigate to ‘Code Snippets’ » ‘Add Snippet’ within your WordPress dashboard.
3. **Select PHP Snippet:** Choose ‘PHP Snippet’ from the ‘Code Type’ dropdown menu.
4. **Paste the PHP Code:** Copy and paste the following code into the WPCode editor:

“`php
function getTwitterFollowers($screenName = ‘wpbeginner’)
{
// some variables
$consumerKey = ‘YOUR_CONSUMER_KEY’;
$consumerSecret = ‘YOUR_CONSUMER_SECRET’;
$token = get_option(‘cfTwitterToken’);

// get follower count from cache
$numberOfFollowers = get_transient(‘cfTwitterFollowers’);

// cache version does not exist or expired
if (false === $numberOfFollowers) {
// getting new auth bearer only if we don’t have one
if(!$token) {
// preparing credentials
$credentials = $consumerKey . ‘:’ . $consumerSecret;
$toSend = base64_encode($credentials);

// http post arguments
$args = array(
‘method’ => ‘POST’,
‘httpversion’ => ‘1.1’,
‘blocking’ => true,
‘headers’ => array(
‘Authorization’ => ‘Basic ‘ . $toSend,
‘Content-Type’ => ‘application/x-www-form-urlencoded;charset=UTF-8’
),
‘body’ => array( ‘grant_type’ => ‘client_credentials’ )
);

add_filter(‘https_ssl_verify’, ‘__return_false’);
$response = wp_remote_post(‘https://api.twitter.com/oauth2/token’, $args);

$keys = json_decode(wp_remote_retrieve_body($response));

if($keys) {
// saving token to wp_options table
update_option(‘cfTwitterToken’, $keys->access_token);
$token = $keys->access_token;
}
}
// we have bearer token wether we obtained it from API or from options
$args = array(
‘httpversion’ => ‘1.1’,
‘blocking’ => true,
‘headers’ => array(
‘Authorization’ => “Bearer $token”
)
);

add_filter(‘https_ssl_verify’, ‘__return_false’);
$api_url = “https://api.twitter.com/1.1/users/show.json?screen_name=$screenName”;
$response = wp_remote_get($api_url, $args);

if (!is_wp_error($response)) {
$followers = json_decode(wp_remote_retrieve_body($response));
$numberOfFollowers = $followers->followers_count;
} else {
// get old value and break
$numberOfFollowers = get_option(‘cfNumberOfFollowers’);
// uncomment below to debug
//die($response->get_error_message());
}

// cache for an hour
set_transient(‘cfTwitterFollowers’, $numberOfFollowers, 1*60*60);
update_option(‘cfNumberOfFollowers’, $numberOfFollowers);
}

return $numberOfFollowers;
}

echo getTwitterFollowers();
“`

5. **Replace Placeholders:** In the code, substitute your actual API key and secret:

“`php
$consumerKey = ‘YOUR_CONSUMER_KEY’;
$consumerSecret = ‘YOUR_CONSUMER_SECRET’;
“`

6. **Set the Twitter Username:** Replace `’wpbeginner’` with the desired Twitter username (without the @ symbol).

7. **Activate the Code Snippet:** Toggle the ‘Inactive’ switch to ‘Active’ and click on ‘Save Snippet’.

8. **Generate a Shortcode:** Scroll to the ‘Insertion’ section and click on the ‘Shortcode’ button. This will generate a shortcode that you can use to display the follower count.

**Step 3: Display Your Follower Count**

Now, you can easily embed the follower count anywhere on your website:

1. **Add the Shortcode:** In the WordPress block editor, add a ‘Shortcode’ block and paste the generated shortcode.
2. **Provide Context:** It’s best practice to add text explaining the displayed number. For example, “Follow us on Twitter: [Shortcode] followers”
3. **Update or Publish:** Save your changes by clicking ‘Update’ or ‘Publish’ to make the follower count visible on your website.

**Bonus Tip: Optimize Your Twitter Marketing**

Now that you’ve successfully displayed your Twitter follower count, consider these strategies to further enhance your social media presence:

* **Add Twitter Share Buttons:** Include share buttons on your website, making it effortless for visitors to share your content on Twitter.
* **Promote Your Twitter Page with Popups:** Use popups to increase your Twitter followers and drive traffic to your profile.

**Conclusion**

Displaying your Twitter followers count as text on your WordPress website is a simple but effective strategy for enhancing social proof and credibility. It signals trustworthiness and encourages user engagement. By following the steps outlined in this guide, you can easily add this powerful element to your WordPress site.

Remember, social media is a dynamic landscape, so continuously analyze your performance, adapt your strategies, and leverage the power of social proof to build a thriving online presence.

**FAQs**

**H2: Frequently Asked Questions**

**H3: How can I display the follower count for multiple Twitter users?**

**P:** The provided code is designed for a single Twitter account. To display counts for multiple users, you’ll need to modify the code to accept an array of usernames and iterate through them. You can also explore dedicated social media plugins that offer this functionality.

**H3: Can I customize the text output for the follower count?**

**P:** Yes, you can. The code currently just outputs the number. To customize the text, you can add your desired text before or after the `echo` statement.

**H3: How often is the follower count updated?**

**P:** The code utilizes caching to reduce API calls. By default, the follower count is cached for an hour. You can adjust this interval within the code if needed.

**H3: What if the Twitter API changes?**

**P:** Twitter APIs are subject to change. It’s essential to monitor Twitter documentation and updates for any changes.

**H3: How can I display the follower count in a specific widget or area?**

**P:** You can use shortcodes with any WordPress widget or element that supports shortcode functionality. For example, use the Text widget or a shortcode-enabled page builder element.

**H3: Can I style the follower count to match my website’s design?**

**P:** Yes, you can use CSS to style the follower count. You can either add the CSS directly to your theme’s stylesheet or use a plugin like WPCode to manage your CSS code.

**H3: What are some best practices for displaying the follower count?**

**P:** Place it in a prominent location on your website, such as the sidebar, footer, or within a social media widget. Provide context with text and ensure it is visually appealing and consistent with your brand.

**H3: Can I use this code on a non-WordPress site?**

**P:** While the code is specifically designed for WordPress, you can adapt it for use with other PHP applications. You’ll need to modify it to match the specific environment and adjust any dependencies.

**H3: Is it possible to get the follower count in a format like “140,029” instead of “140029”?**

**P:** Yes, you can use the `number_format()` function to format the follower count with commas. Add the following line after retrieving the `$numberOfFollowers`:

“`php
$numberOfFollowers = number_format($numberOfFollowers);
“`

**H3: How can I display the follower count in a table format?**

**P:** You can create a table within your WordPress post or page and use shortcodes to display the follower count for each Twitter user. Use HTML table tags (`

`, `

`, `

`) to structure the table and insert the shortcodes within the table cells.

**H3: What if the API call fails to retrieve the follower count?**

**P:** The code includes error handling to gracefully handle cases where the API call fails. You can further customize the error handling to display a message or take alternative actions.

**H3: Is there a way to display the follower count without using an API?**

**P:** While API access is the most reliable way to get the follower count, you can try using web scraping techniques to extract the data from Twitter’s website. However, this method is less reliable and may violate Twitter’s terms of service.

**H3: What are some alternative ways to display social proof on my website?**

**P:** Besides the follower count, you can showcase social proof through:

* **Social Media Feeds:** Display live updates from your Twitter account.
* **Testimonials:** Include customer or user reviews.
* **Awards and Recognition:** Showcase any awards or recognition you’ve received.

**If you’re interested in learning more about tech news and WordPress development, feel free to visit my website: [www.naveedahmed.me](www.naveedahmed.me).**

Posted in All
Need help for wordpress ?
Contact me
https://whatreligionisinfo.com/ https://howtobakeandcook.com/ https://howdidcelebdie.com/