/** ------------------------------------------- * Yoast Open Graph locale (Securities.io) * ------------------------------------------- */ /* Detect current page language from first path segment. */ function seci_detect_lang_from_path_simple(): string { $path = trim(parse_url((is_ssl() ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? '') . ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?? '', '/'); $seg = explode('/', $path)[0] ?? ''; if (preg_match('~^[a-z]{2}(-[a-z]{2})?$~i', $seg)) { return strtolower($seg); } return 'en'; // default at root } /* Map site lang → WP/OG locale codes used by Yoast. Extend if you add languages. */ function seci_lang_to_og_locale(string $lang): string { $lang = strtolower($lang); $map = array( 'en' => 'en_US', 'en-us' => 'en_US', 'en-gb' => 'en_GB', 'fr' => 'fr_FR', 'es' => 'es_ES', 'de' => 'de_DE', 'it' => 'it_IT', 'nl' => 'nl_NL', 'pt' => 'pt_PT', 'pt-br' => 'pt_BR', 'pl' => 'pl_PL', 'sv' => 'sv_SE', 'no' => 'nb_NO', 'da' => 'da_DK', 'fi' => 'fi_FI', 'cs' => 'cs_CZ', 'sk' => 'sk_SK', 'sl' => 'sl_SI', 'ro' => 'ro_RO', 'hu' => 'hu_HU', 'tr' => 'tr_TR', 'el' => 'el_GR', 'ru' => 'ru_RU', 'uk' => 'uk_UA', 'ar' => 'ar', // generic Arabic if you use /ar/ 'he' => 'he_IL', 'ja' => 'ja_JP', 'ko' => 'ko_KR', 'zh' => 'zh_CN', 'zh-cn' => 'zh_CN', 'zh-tw' => 'zh_TW', ); return $map[$lang] ?? 'en_US'; } /* Force Yoast to use the locale inferred from the URL’s language prefix. */ add_filter('wpseo_locale', function ($locale) { return seci_lang_to_og_locale(seci_detect_lang_from_path_simple()); }, 99); add_filter('wpseo_og_locale', function ($locale) { return seci_lang_to_og_locale(seci_detect_lang_from_path_simple()); }, 99); Best Of Archives - Unite.AI
Følg os

Best Of