How to Display Twitter Followers Count as Text in WordPress

Do you want to show your Twitter fans count as text in WordPress?

By revealing that many individuals follow you on social networks, you can motivate visitors to trust your site. Even mutter, by showing ththeseetails as text, you hacantilize it anywhere on your site, consisting of inside your posts and pages.

This post will demonstrate how to tour Twitter fans count as text in WordPress.

Why do Display Twitter Followers count as Text in WordPress?

You might have observed that numerous popular blog sites, influencers, and brand names happily demonstrate how to follow them on social networks.

IfSupposeisitors see great deals of individuals following you on social networks, In that case, they are most likely to trust your service and see you as a professional in your blogging-specific niche.

Many of the very best social network plugins enable you to reveal the overall fan count in ingrained feeds, buttons, banners, and more.

Sometimes, you might want to reveal the number as plain text. This allows you to include the fan count in the honor article, footer, or anywhere else on your WordPress blog site or site.

With that in mind, let’s see how you can show your Twitter fan count as text in WordPress.

Action 1: Get a Twitter API Key and Secret

To get your fan count, you need to access the Twitter API by producing an API Key and Secret.

To get this info, head to the Twitter Developers Portal  and click ‘Sign up for Free Account.’

Registering for a Twitter Developers account

You can now enter some details about how you prepare to utilize the Twitter API. It’s an excellent concept to offer as much information as possible. Twitter will evaluate these details and might erase your account if they do not comprehend how you use their API.

After that, check out the conditions. If you m prepared than happy to continue; click the ‘Submit’ button.

Accepting the Twitter Developers terms

You will now see the Developer Portal. Click to broaden the ‘Projects & Apps’ area in the left-hand menu. Choose ‘Overview.’

You can now proceed and click ‘Add App.’

How to produce a Twitter app

After that, enter the name you wish to utilize for your Twitter app. This is simply for your referral, so you can use anything you want, click the ‘Next’ button.

Calling a Twitter application

Twitter will now reveal an API secret and API Secret. This is the only time you will see this info, so take it down someplace safe.

We suggest including the esessentialsnd secret to a password supervisor for additional security.

Getting a Twitter API secret and secret

Action 2: Add Custom Code to Your WordPress Website

The most convenient method to include the Twitter fan count on toonour website is PHP code.

For security factors, WordPress does not enable you to include PHP code straight to your pages and posts, However it does permit shortcodes. This indicates you can produce a custom-made shortcode and connect it to your PHP code.

The most convenient method to include customized shortcodes in WordPress is by utilizing WPCodeThis plugin enables you to produce as lomanyhortcodes as you desire and, afthenonnect them to various areas of PHP code.

The first thing you must do is set up and trigger the complimentary WPCode pl plugin forore information; see our detailed guide on how to set up a WordPress plugin.

Upon activation, head over to Code Snippets” Include Snippet

Including custom-made shortcode to your WordPress site

Here, you will see all the ready-made bits you can contribute to your site. These consist of bits enabling you to turn off WordPress remarks, upload files that WordPress does not support by default, and more.

Because you are producing a brand-new bit, hover your mouse over ‘Add Your Custom Code.’ Simply click on ‘Use bit.’

Including a custom-made code bit to WordPress utilizing WPCode

To begin, key in a title for the customized code bit. This can be anything that assists you recin recognizing bits in the WordPress control panel.

After that, you need to open the ‘Code Type’ dropdown and choose ‘PHP Snippet.’

Including a PHP bit to WordPress utilizing custom-made code

In the code editor, merely paste the following PHP code:

 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(); ?>

In the code above, makesuren you change the following placeholders with your own API secret and API trick:

     $consumerKey = 'YOUR_CONSUMER_KEY';     $consumerSecret = 'YOUR_CONSUMER_SECRET';

You will likewise require to change ‘wpbeginner’ with the Twitter account that you wish to utilize. This can be any Twitter account consisting of funds that you do not own:

 function getTwitterFollowers($screenName = 'wpbeginner')

To get the Twername, merely open the Twitter profile in a brand-new tab. You will discover the username in the URL and the profile header:

Getting a Twitter username

With that done, change back to the WordPress control panel. Here, merely click the ‘Inactive’ toggle so that it alters to ‘Active.’

You can then go on and click the ‘Save bit’ button.

Showing the Twitter fan count utilizing WPCode

With that done, scroll to the ‘Insertion’ area.

WPCode can instantly include your code in various areas, such as after every post, front end just, or admin just. To get the shortcode, click the ‘Shortcode’ button.

Including a Twitter fan count to WordPress utilizing a customized shortcode

You can now utilize the shortcode to include social evidence toonny the page or post.

Mlick the ‘+’ button in the block editor and key in ‘Shortcode.’ Pick the Shortcode block to include on the page or post when it appears.

How to include a shortcode block to WordPress

You can now include the shortcode in the block.

Simply understand that the shortcode deals the overall fan count, so you will usually wish to include some text describing what number to find out more on how to put the shortcode; please see our guide on hoincluding shortcode in WordPress.

When you enjoy wow the page is established, you can make the fan count live by clicking either the ‘Update’ or ‘Publish’ button.

You will see the fan count live if you visit your WordPress site.

An example of a Twitter fan count, produced utilizing WPCode

We hope this tutorial helped you find out how to show your Twitter fans count as text in WordPress. You might wish to find out how to develop a custom-made Instagram image feed in WordPress or look at our specialist selects for the best Twitter plugins for WordPress.

SVisionary

Leave a Reply

“You're more than just a customer; you're the hero of our stories.”

Subscribe our

Weekly Posts

to receive a variety of interesting content, special promotions and exclusive discounts. Stay ahead of the game with our exclusive updates on the latest AI technology and the trend of the digital world!