örnek olması açısından buda euro ile birlikte

<?php
/*
Plugin Name: Doviz Değerleri (Bayrak Temalı)
Description: Türkiye Merkez Bankası verilerine göre döviz değerlerini bayrak temalı olarak gösterir.
Version: 1.2
Author: Mustafa Çakar
Demo adres: https://www.alaiyehaber.com
*/

function doviz_degerleri() {
    // Cache key and cache duration (30 minutes)
    $cache_key = 'tcmb_doviz_kurlari';
    $cached_response = get_transient($cache_key);

    if ($cached_response === false) {
        // Fetch data from TCMB
        $url = 'https://www.tcmb.gov.tr/kurlar/today.xml';
        $response = wp_remote_get($url);

        if (is_wp_error($response)) {
            return 'Veri çekilemedi.';
        }

        // Store response in cache
        set_transient($cache_key, $response, 30 * MINUTE_IN_SECONDS);
    } else {
        $response = $cached_response;
    }

    // Parse XML
    $xml = simplexml_load_string($response['body']);
    if (!$xml) {
        return 'Veri işlenemedi.';
    }

    // USD ve EUR verilerini alalım
    $usd = $xml->Currency[0]; // USD verisi
    $eur = $xml->Currency[3]; // EUR verisi (pozisyon XML'de değişebilir)

    // Dolar verileri
    $usd_satis = (float) $usd->ForexSelling;
    $usd_son = (float) get_option('usd_son_deger', $usd_satis);
    $usd_renk = $usd_satis > $usd_son ? 'green' : ($usd_satis < $usd_son ? 'red' : 'gray');

    // Euro verileri
    $eur_satis = (float) $eur->ForexSelling;
    $eur_son = (float) get_option('eur_son_deger', $eur_satis);
    $eur_renk = $eur_satis > $eur_son ? 'green' : ($eur_satis < $eur_son ? 'red' : 'gray');

    // Son değerleri kaydet
    update_option('usd_son_deger', $usd_satis);
    update_option('eur_son_deger', $eur_satis);

    // Bayrakların URL'leri
    $usd_flag = 'https://upload.wikimedia.org/wikipedia/en/a/a4/Flag_of_the_United_States.svg';
    $eur_flag = 'https://upload.wikimedia.org/wikipedia/commons/b/b7/Flag_of_Europe.svg';

    // Döviz bilgilerini bayraklarla birlikte gösterelim
    return "
    <div style='font-size: 20px;'>
        <div style='display: flex; align-items: center; margin-bottom: 10px;'>
            <img src='" . esc_url($usd_flag) . "' alt='USD Flag' style='width: 40px; height: 25px; margin-right: 10px;' />
            <span style='color: " . esc_attr($usd_renk) . ";'>
                ABD Doları Satış: " . esc_html($usd_satis) . " TL
            </span>
        </div>
        <div style='display: flex; align-items: center;'>
            <img src='" . esc_url($eur_flag) . "' alt='EUR Flag' style='width: 40px; height: 25px; margin-right: 10px;' />
            <span style='color: " . esc_attr($eur_renk) . ";'>
                Euro Satış: " . esc_html($eur_satis) . " TL
            </span>
        </div>
    </div>";
}

function doviz_degerleri_shortcode() {
    return doviz_degerleri();
}

add_shortcode('doviz_degeri', 'doviz_degerleri_shortcode');