Title: format_code_lang
Published: April 25, 2014
Last modified: August 20, 2026

---

# format_code_lang( string $code = `''` ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#user-contributed-notes)

Returns the language for a language code.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#parameters)󠁿

 `$code`stringoptional

The two-letter language code.

Default:`''`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#return)󠁿

 string The language corresponding to $code if it exists. If it does not exist, 
then the first two letters of $code is returned.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#source)󠁿

    ```php
    function format_code_lang( $code = '' ) {
    	$code       = strtolower( substr( $code, 0, 2 ) );
    	$lang_codes = array(
    		'aa' => 'Afar',
    		'ab' => 'Abkhazian',
    		'af' => 'Afrikaans',
    		'ak' => 'Akan',
    		'sq' => 'Albanian',
    		'am' => 'Amharic',
    		'ar' => 'Arabic',
    		'an' => 'Aragonese',
    		'hy' => 'Armenian',
    		'as' => 'Assamese',
    		'av' => 'Avaric',
    		'ae' => 'Avestan',
    		'ay' => 'Aymara',
    		'az' => 'Azerbaijani',
    		'ba' => 'Bashkir',
    		'bm' => 'Bambara',
    		'eu' => 'Basque',
    		'be' => 'Belarusian',
    		'bn' => 'Bengali',
    		'bh' => 'Bihari',
    		'bi' => 'Bislama',
    		'bs' => 'Bosnian',
    		'br' => 'Breton',
    		'bg' => 'Bulgarian',
    		'my' => 'Burmese',
    		'ca' => 'Catalan; Valencian',
    		'ch' => 'Chamorro',
    		'ce' => 'Chechen',
    		'zh' => 'Chinese',
    		'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
    		'cv' => 'Chuvash',
    		'kw' => 'Cornish',
    		'co' => 'Corsican',
    		'cr' => 'Cree',
    		'cs' => 'Czech',
    		'da' => 'Danish',
    		'dv' => 'Divehi; Dhivehi; Maldivian',
    		'nl' => 'Dutch; Flemish',
    		'dz' => 'Dzongkha',
    		'en' => 'English',
    		'eo' => 'Esperanto',
    		'et' => 'Estonian',
    		'ee' => 'Ewe',
    		'fo' => 'Faroese',
    		'fj' => 'Fijjian',
    		'fi' => 'Finnish',
    		'fr' => 'French',
    		'fy' => 'Western Frisian',
    		'ff' => 'Fulah',
    		'ka' => 'Georgian',
    		'de' => 'German',
    		'gd' => 'Gaelic; Scottish Gaelic',
    		'ga' => 'Irish',
    		'gl' => 'Galician',
    		'gv' => 'Manx',
    		'el' => 'Greek, Modern',
    		'gn' => 'Guarani',
    		'gu' => 'Gujarati',
    		'ht' => 'Haitian; Haitian Creole',
    		'ha' => 'Hausa',
    		'he' => 'Hebrew',
    		'hz' => 'Herero',
    		'hi' => 'Hindi',
    		'ho' => 'Hiri Motu',
    		'hu' => 'Hungarian',
    		'ig' => 'Igbo',
    		'is' => 'Icelandic',
    		'io' => 'Ido',
    		'ii' => 'Sichuan Yi',
    		'iu' => 'Inuktitut',
    		'ie' => 'Interlingue',
    		'ia' => 'Interlingua (International Auxiliary Language Association)',
    		'id' => 'Indonesian',
    		'ik' => 'Inupiaq',
    		'it' => 'Italian',
    		'jv' => 'Javanese',
    		'ja' => 'Japanese',
    		'kl' => 'Kalaallisut; Greenlandic',
    		'kn' => 'Kannada',
    		'ks' => 'Kashmiri',
    		'kr' => 'Kanuri',
    		'kk' => 'Kazakh',
    		'km' => 'Central Khmer',
    		'ki' => 'Kikuyu; Gikuyu',
    		'rw' => 'Kinyarwanda',
    		'ky' => 'Kirghiz; Kyrgyz',
    		'kv' => 'Komi',
    		'kg' => 'Kongo',
    		'ko' => 'Korean',
    		'kj' => 'Kuanyama; Kwanyama',
    		'ku' => 'Kurdish',
    		'lo' => 'Lao',
    		'la' => 'Latin',
    		'lv' => 'Latvian',
    		'li' => 'Limburgan; Limburger; Limburgish',
    		'ln' => 'Lingala',
    		'lt' => 'Lithuanian',
    		'lb' => 'Luxembourgish; Letzeburgesch',
    		'lu' => 'Luba-Katanga',
    		'lg' => 'Ganda',
    		'mk' => 'Macedonian',
    		'mh' => 'Marshallese',
    		'ml' => 'Malayalam',
    		'mi' => 'Maori',
    		'mr' => 'Marathi',
    		'ms' => 'Malay',
    		'mg' => 'Malagasy',
    		'mt' => 'Maltese',
    		'mo' => 'Moldavian',
    		'mn' => 'Mongolian',
    		'na' => 'Nauru',
    		'nv' => 'Navajo; Navaho',
    		'nr' => 'Ndebele, South; South Ndebele',
    		'nd' => 'Ndebele, North; North Ndebele',
    		'ng' => 'Ndonga',
    		'ne' => 'Nepali',
    		'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
    		'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
    		'no' => 'Norwegian',
    		'ny' => 'Chichewa; Chewa; Nyanja',
    		'oc' => 'Occitan, Provençal',
    		'oj' => 'Ojibwa',
    		'or' => 'Oriya',
    		'om' => 'Oromo',
    		'os' => 'Ossetian; Ossetic',
    		'pa' => 'Panjabi; Punjabi',
    		'fa' => 'Persian',
    		'pi' => 'Pali',
    		'pl' => 'Polish',
    		'pt' => 'Portuguese',
    		'ps' => 'Pushto',
    		'qu' => 'Quechua',
    		'rm' => 'Romansh',
    		'ro' => 'Romanian',
    		'rn' => 'Rundi',
    		'ru' => 'Russian',
    		'sg' => 'Sango',
    		'sa' => 'Sanskrit',
    		'sr' => 'Serbian',
    		'hr' => 'Croatian',
    		'si' => 'Sinhala; Sinhalese',
    		'sk' => 'Slovak',
    		'sl' => 'Slovenian',
    		'se' => 'Northern Sami',
    		'sm' => 'Samoan',
    		'sn' => 'Shona',
    		'sd' => 'Sindhi',
    		'so' => 'Somali',
    		'st' => 'Sotho, Southern',
    		'es' => 'Spanish; Castilian',
    		'sc' => 'Sardinian',
    		'ss' => 'Swati',
    		'su' => 'Sundanese',
    		'sw' => 'Swahili',
    		'sv' => 'Swedish',
    		'ty' => 'Tahitian',
    		'ta' => 'Tamil',
    		'tt' => 'Tatar',
    		'te' => 'Telugu',
    		'tg' => 'Tajik',
    		'tl' => 'Tagalog',
    		'th' => 'Thai',
    		'bo' => 'Tibetan',
    		'ti' => 'Tigrinya',
    		'to' => 'Tonga (Tonga Islands)',
    		'tn' => 'Tswana',
    		'ts' => 'Tsonga',
    		'tk' => 'Turkmen',
    		'tr' => 'Turkish',
    		'tw' => 'Twi',
    		'ug' => 'Uighur; Uyghur',
    		'uk' => 'Ukrainian',
    		'ur' => 'Urdu',
    		'uz' => 'Uzbek',
    		've' => 'Venda',
    		'vi' => 'Vietnamese',
    		'vo' => 'Volapük',
    		'cy' => 'Welsh',
    		'wa' => 'Walloon',
    		'wo' => 'Wolof',
    		'xh' => 'Xhosa',
    		'yi' => 'Yiddish',
    		'yo' => 'Yoruba',
    		'za' => 'Zhuang; Chuang',
    		'zu' => 'Zulu',
    	);

    	/**
    	 * Filters the language codes.
    	 *
    	 * @since MU (3.0.0)
    	 *
    	 * @param string[] $lang_codes Array of key/value pairs of language codes where key is the short version.
    	 * @param string   $code       A two-letter designation of the language.
    	 */
    	$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
    	return strtr( $code, $lang_codes );
    }
    ```

[View all references](https://developer.wordpress.org/reference/file/wp-admin/includes/ms.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-admin/includes/ms.php#L352)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-admin/includes/ms.php#L352-L552)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#hooks)󠁿

 [apply_filters( ‘lang_codes’, string[] $lang_codes, string $code )](https://developer.wordpress.org/reference/hooks/lang_codes/)

Filters the language codes.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [mu_dropdown_languages()](https://developer.wordpress.org/reference/functions/mu_dropdown_languages/)`wp-admin/includes/ms.php` |

Generates and displays a drop-down of available languages.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#comment-content-1537)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/format_code_lang/#comment-1537)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%23comment-1537)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%23comment-1537)
 4.  **Example**
 5.      ```php
         $code     = 'da';
         $language = format_code_lang( $code );
     
         echo $language; // 'Danish'
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%3Freplytocom%3D1537%23feedback-editor-1537)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/format_code_lang/?output_format=md#comment-content-2768)
 8.    [Denis Žoljom](https://profiles.wordpress.org/dingo_d/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/format_code_lang/#comment-2768)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%23comment-2768)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%23comment-2768)
 10. One thing to note is that this function works only in the multisite environment.
     So you cannot use it in your regular plugins on non multisite install, othervise
     you’ll get a `Uncaught Error: Call to undefined function format_code_lang()` error.
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F%3Freplytocom%3D2768%23feedback-editor-2768)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fsummer-heart-0930.chufeiyun1688.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_code_lang%2F)
before being able to contribute a note or feedback.