How to show live tennis scores on a WordPress site

Tennis clubs, coaching academies and sports blogs often want the same thing on a WordPress site. They want today’s scores, updated while the matches are on. There are plugins that embed a third-party widget, but they bring someone else’s styling, ads and tracking onto your pages. Building it yourself takes less code than most people expect, and it keeps the design in your theme’s hands.
Table of Contents
ToggleThis guide covers where the data comes from and how to fetch it without slowing the site. It also covers how to display it in a way that works with any theme.
Pick a data source first
Everything depends on the feed behind the scores. Before writing any code, check three things about a tennis data API. Which tours it covers, so the matches your readers follow are there. How it delivers updates, usually a REST endpoint you poll or a stream that pushes changes. And what it allows you to show publicly on a website.
If you plan to add results pages or player records later, check the history as well. Some providers keep only recent results. Others, such as Live Tennis API, offer point-by-point tennis data since 2013. With that you can show how a past match unfolded, point by point.
Keep the API key on the server
Never put an API key in JavaScript that runs in the visitor’s browser. Anyone can read it there. In WordPress the safe place is the server. Store the key in wp-config.php as a constant, or in an option only administrators can edit. Then make every request to the data provider from PHP.
That one decision also solves the next problem, which is load.
Fetch once, serve everyone
If every page view called the tennis API, a busy afternoon would mean thousands of identical requests. WordPress has a built-in answer in the Transients API. Fetch the scores with wp_remote_get, store the response with set_transient for a short time, and serve every visitor from that stored copy until it expires.
For live scores, an expiry of 30 to 60 seconds is a sensible start. For finished results, an hour or more is fine. The visitor sees fresh data, and the provider sees one request per minute, not one per page view.
On a site with a persistent object cache such as Redis, transients are kept in memory and the cost is close to nothing. Without one, they sit in the options table, which still works well at this scale.
Display it with a shortcode or a block
The simplest way to place the scores in a post or page is a shortcode. Register it with add_shortcode, have it read the cached data, and return the markup. An editor can then type the shortcode wherever the scores belong, with no code in the post itself.
If your site uses the block editor heavily, a small custom block does the same job with a preview in the editor. Either way, keep the markup plain: a list or a table with clear class names. Your theme’s stylesheet then handles colours, fonts and spacing, so the scores look like part of the site.
Refresh without reloading the page
A visitor who leaves the page open will want the score to change in front of them. You do not need to reload the whole page for that. Add a small REST route with register_rest_route that returns the same cached data as JSON. Then add a few lines of JavaScript that call it every 30 seconds and update the numbers in place.
Because the route reads the transient, the browser polling adds no extra calls to the data provider. The API key never leaves the server.
Handle the awkward cases
Tennis produces states that break naive code. Rain suspends a match for hours. A player retires mid-set. A match is cancelled before it starts. Make sure each status from the feed maps to something readable on the page, such as “Suspended” or “Retired”, and not an empty score.
Plan for the provider being unreachable too. If a fetch fails, keep showing the last good data with its time, and do not cache the error. A short note such as “updated 2 minutes ago” is better than a blank box.
Test before match day
Try the setup with a few real matches before you rely on it. Check the scores against the official results afterwards and watch the page on a phone. Look at your server’s response times while the cache is cold, too. Most problems show up in the first live session, and it is better to find them on a quiet weekday than during a final.
A small plugin of your own, built this way, gives you live scores that match your theme, load fast and stay under your control.
