Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
WordPress Theme Development

API Data in WordPress Themes

Display third-party API data in themes with caching and safe fallbacks.

API Data in WordPress Themes — a practical guide to WordPress theme external API with clear examples you can reuse in real projects.

WordPress Theme Development Series (58/96). Prefer one article? Read the complete WordPress theme development tutorial.

Short description

Fetch on the server when possible, cache with transients, and never expose secrets in frontend JS.

Transient-cached fetch

$data = get_transient('acme_api_data');
if (false === $data) {
  $res = wp_remote_get('https://api.example.com/data', ['timeout' => 10]);
  $data = is_wp_error($res) ? [] : json_decode(wp_remote_retrieve_body($res), true);
  set_transient('acme_api_data', $data, 15 * MINUTE_IN_SECONDS);
}

Leave a reply

Your email address will not be published. Required fields are marked *