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

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!

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.

Huobi App download requires selecting the corresponding method according to the operating system. iOS users should use overseas Apple ID to log in to the App Store to search and install, while Android users download the APK file through the official website and allow the installation of applications from unknown sources. To ensure security, you must master the methods of identifying the authenticity of the official website: check the official website, check the HTTPS security certificate, follow the official announcement channels, avoid clicking on unknown links, and confirm the source of the verification code. In addition, when using the App, you should pay attention to setting a strong password and enabling two-factor verification, regularly update the version, understand transaction risks, beware of fraud, backup mnemonics and private keys, and contact the official customer service if you encounter problems.

As a world-renowned digital asset trading platform, OKX's web version login portal is the core channel for users to access services.

Bitcoin’s price seems to be repeating the trend that has been around in the past, and traders are closely watching this trend. Over the past seven weeks, Bitcoin (BTC) prices have recorded seven consecutive positive lines on the weekly chart. If you feel familiar, it is because this happened in 2021 and 2023. Similar to that time, the K-line in the eighth week turned into a negative line. This recurring technology pattern has attracted the attention of crypto analyst CryptoPatel and released relevant analysis on the X platform. He showed a chart showing that Bitcoin’s upward momentum tended to stagnate after the seventh green candle. "Bitcoin just completed the seventh consecutive weekly positive line...but it did not continue to the eighth positive line." He pointed out in his tweet. In addition, about

Airdrops in the cryptocurrency field are a marketing promotion method for the project to distribute a certain number of tokens for free to community members or potential users. In this way, the project party hopes to increase the visibility of the tokens and attract more users to participate in the project, thereby expanding the size of the community and increasing the liquidity of the tokens. For users, airdrops provide opportunities to obtain project tokens without initial investment, and are one of the ways to get in touch with and understand new projects in the early stage.

How do novice users choose a safe and reliable stablecoin platform? This article recommends the Top 10 stablecoin platforms in 2025, including Binance, OKX, Bybit, Gate.io, HTX, KuCoin, MEXC, Bitget, CoinEx and ProBit, and compares and analyzes them from dimensions such as security, stablecoin types, liquidity, user experience, fee structure and additional functions. The data comes from CoinGecko, DefiLlama and community evaluation. It is recommended that novices choose platforms that are highly compliant, easy to operate and support Chinese, such as KuCoin and CoinEx, and gradually build confidence through a small number of tests.

The popular Memecoin project FlokiINU and its high-profile game Valhalla officially become the official partner of the 2025 Baroda Premier League. The well-known Memecoin project FlokiINU has announced a major cooperation plan that is expected to attract widespread attention in the cryptocurrency and sports worlds. The project and its core product, the upcoming multiplayer online game Valhalla, has officially become the official partner of the 2025 Baroda Emerier League. The cricket event will be held from June 15 to 29, with a total of 24 matches and will be broadcast on StarSportsKhel and Fancode platforms. This cooperation is
