# Choose the x-default Language for WPML hreflang Tags

> Points WPML's x-default hreflang tag at the language you choose, for example English, instead of the site's default language.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: wpml, hreflang, seo
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpml-hreflang-x-default/

## Code

```php
$wpide_x_default = 'en'; // hreflang code to use as x-default.

add_filter( 'wpml_hreflangs', function ( $hreflangs ) use ( $wpide_x_default ) {
    if ( is_array( $hreflangs ) && ! empty( $hreflangs[ $wpide_x_default ] ) ) {
        $hreflangs['x-default'] = $hreflangs[ $wpide_x_default ];
    }

    return $hreflangs;
} );
```

## Notes

Use the hreflang code as WPML prints it (en, en-us, fr…). If that language has no translation of the page, the tag is left as WPML set it.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Choose the x-default Language for WPML hreflang Tags" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
