Aşağıdaki kodu functions.php ekleyin sonrasında kurların görünmesini istediğiniz alana bu kısa kodu ekleyin [doviz_kurlari]:

<?php
function get_exchange_rates() {
$tcmb_url = "https://www.tcmb.gov.tr/kurlar/today.xml";

// XML verisini çek
$xml = simplexml_load_file($tcmb_url);

if (!$xml) {
return "Döviz kurları alınamadı.";
}

// Döviz kurlarını almak için bir dizi oluştur
$currencies = [
"USD" => "Amerikan Doları",
"EUR" => "Euro",
"GBP" => "İngiliz Sterlini"
];

$output = "<table border='1' style='width:100%; text-align:center;'>";
$output .= "<tr><th>Döviz</th><th>Alış</th><th>Satış</th></tr>";

foreach ($xml->Currency as $currency) {
$code = (string) $currency['CurrencyCode'];

if (array_key_exists($code, $currencies)) {
$name = $currencies[$code];
$forexBuying = (string) $currency->ForexBuying;
$forexSelling = (string) $currency->ForexSelling;

$output .= "<tr><td>{$name} ({$code})</td><td>{$forexBuying} ₺</td><td>{$forexSelling} ₺</td></tr>";
}
}

$output .= "</table>";

return $output;
}

// WordPress Shortcode için fonksiyon
function display_exchange_rates() {
return get_exchange_rates();
}
add_shortcode('doviz_kurlari', 'display_exchange_rates');