Display weekly EIA diesel prices in WordPress

Publish the U.S. on-highway diesel average from EIA on a WordPress site. Fetch it in PHP, cache the observation and show its survey date and unit.

Publish a dated U.S. retail diesel price

  1. Store your OilPriceAPI key as OILPRICEAPI_KEY in wp-config.php or your hosting secret settings. Run the request in your server-side plugin or shortcode.
  2. Check for a WordPress error and require HTTP 200 before decoding the response. Cache a valid quote with a transient. If the fetch fails, retain the previous dated value or show that the series is unavailable.
  3. Display the EIA weekly U.S. on-highway diesel average with USD per gallon, its source date and EIA attribution. Other series require their own public-display rights.

Server-side PHP request

$response = wp_remote_get(
    "https://api.oilpriceapi.com/v1/prices/latest?by_code=DIESEL_RETAIL_USD",
    array(
        "timeout" => 10,
        "headers" => array("Authorization" => "Token " . OILPRICEAPI_KEY),
    )
);

Latest DIESEL_RETAIL_USD from the API

$5.94per gallon

As of 2026-11-16 12:00 UTC

WordPress caching and shortcode walkthroughCheck display rights by data source