# Polylang hreflang: Set Which Language Is x-default

> Adds or replaces the x-default hreflang link Polylang prints, pointing it at the language you choose so search engines know which version to show everyone else.

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

## Code

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

add_filter( 'pll_rel_hreflang_attributes', 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 Polylang prints for that language (often en or en-US; view your page source to check).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Polylang hreflang: Set Which Language Is x-default" 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/
