How to show Twitter followers and more in WordPress
Apr 20, 2025 am 06:39 AMWe've written a piece of code before that lets you show the number of Twitter followers, which is contributed by Rarst. In this article, we will share a more advanced and elegant code that allows you to display Twitter followers in WordPress. This script was also contributed by Rust.
feature
This feature is not limited to the number of followers. It can get any non-nested values ??returned by the Twitter users/show API method.
It has two levels of cache:
- The query's value is stored in the database as an array using the WP option, lasting $interval seconds;
- API responses are stored in memory, so you can query as many fields as you like without generating multiple API requests.
This should be safe to use both multiply values ??and multiply users without worrying about running out of API limits.
Tutorial
First open the functions.php file of the theme and add the following code:
functionrarst_twitter_user( $username, $field, $display= false ) {$interval= 3600;$cache= get_option('rarst_twitter_user');$url= 'http://api.twitter.com/1/users/show.json?screen_name='.urlencode($username);if( false == $cache)$cache= array();// if first time request add placeholder and force updateif( !isset( $cache[$username][$field] ) ) {$cache[$username][$field] = NULL;$cache[$username]['lastcheck'] = 0;}// if outdatedif( $cache[$username]['lastcheck'] $value)if( isset($data->$key) )$cache[$username][$key] = $data->$key;$cache[$username]['lastcheck'] = time();}else{$cache[$username]['lastcheck'] = time() 60;}update_option( 'rarst_twitter_user', $cache);}if( false != $display)echo$cache[$username][$field]; return$cache[$username][$field];}
Depend on
Use it with one click in WordPress
usage
After pasting the function, you can now use the code in any WordPress template file you like. Just paste the following code:
echoorarst_twitter_user('wpbeginner', 'name').' has '.rarsst_twitter_user('wpbeginner', 'followers_count').' followers after '.rarsst_twitter_user('wpbeginner', 'statuses_count').' updates.';
Depend on
Use it with one click in WordPress
The above code will display the following:
WPBeginner has 5846 followers after 1300 updates.
The above is the detailed content of How to show Twitter followers and more in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Visiting the latest address to Binance official website can be obtained through search engine query and follow official social media. 1) Use the search engine to enter "Binance Official Website" or "Binance" and select a link with the official logo; 2) Follow Binance's official Twitter, Telegram and other accounts to view the latest posts to get the latest address.

Integrating social media login in the Laravel framework can be achieved by using the LaravelSocialite package. 1. Install the Socialite package: use composerrequirelaravel/socialite. 2. Configure the service provider and alias: add relevant configuration in config/app.php. 3. Set API credentials: Configure social media API credentials in .env and config/services.php. 4. Write controller method: Add redirection and callback methods to handle social media login process. 5. Handle FAQs: Ensure user uniqueness, data synchronization, security and error handling. 6. Optimization practice:

Short-term speculation is suitable for traders with time and pressure resistance, while long-term investment is suitable for holders who believe in the long-term development of the industry. 1. Short-term is suitable for the early stage of a bull market and major events. The core strategies are trend tracking and news arbitrage, and strict stop loss is required. 2. It is suitable for the bottom and disruptive technology in the bear market in the long term. The coin selection criteria are excellent fundamentals and reasonable token economy, and fixed investment and dynamic stop-profit are required.

Combining the latest industry trends and multi-dimensional evaluation data in 2025, the following are the top ten comprehensive AI writing software recommendations, covering mainstream scenarios such as general creation, academic research, and commercial marketing, while taking into account Chinese optimization and localization services:

Nice Comics, an immersive reading experience platform dedicated to creating for comic lovers, brings together a large number of high-quality comic resources at home and abroad. It is not only a comic reading platform, but also a community that connects comic artists and readers and shares comic culture. Through simple and intuitive interface design and powerful search functions, NES Comics allows you to easily find your favorite works and enjoy a smooth and comfortable reading experience. Say goodbye to the long waiting and tedious operations, enter the world of Nice comics immediately and start your comic journey!

In the latest technical analysis, crypto analyst Jonathan Carter posted on X (formerly Twitter), Dogecoin has successfully broken the long-term decline channel. Dogecoin (Doge) price breaks through the down channel pattern, which may shift the trend from bearish to bullish. For cryptocurrencies that have experienced months of downward trend, this seems to be a sign of preparing for the next phase, with analysts now expecting the price to reach $0.44. Dogecoin breakout triggers expectations for $0.44 crypto analyst Jonathan Carter announced on X (formerly Twitter) that Dogecoin is doing

To obtain the official correct address of the Ouyi Exchange APP, you need to go through the following three official channels: 1. Download the official website, visit the official domain name [adid]fe9fc289c3ff0af142b6d3bead98a923[/adid] and download the corresponding system version; 2. Follow the official social media account to obtain the latest download information; 3. Contact the official customer service to confirm. At the same time, users should be alert to phishing websites, check domain names, install antivirus software, enable secondary verification and avoid leakage of personal information to ensure account security.

In 2025, the methods for logging in through the latest online login portal of Binance Binance Exchange are as follows: 1. Visit www.binance.com, 2. Click the "Login" button in the upper right corner, 3. Enter the registered email or mobile phone number and password, 4. Enable two-factor authentication (2FA) and enter the authentication code, 5. After logging in successfully, you can view assets and conduct transactions.
