# Use Each User's Profile Language as Their Polylang Language

> Makes Polylang pick the language set in a logged-in user's profile when it decides which language to show them on the homepage, instead of relying on browser settings.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: polylang, users, locale
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pll-preferred-language-from-profile/

## Code

```php
add_filter( 'pll_preferred_language', function ( $slug ) {
    if ( ! is_user_logged_in() || ! function_exists( 'pll_languages_list' ) ) {
        return $slug;
    }

    $user_locale = get_user_meta( get_current_user_id(), 'locale', true );

    if ( ! $user_locale ) {
        return $slug;
    }

    $locales = pll_languages_list( array( 'fields' => 'locale' ) );
    $slugs   = pll_languages_list( array( 'fields' => 'slug' ) );
    $index   = array_search( $user_locale, $locales, true );

    return false !== $index && isset( $slugs[ $index ] ) ? $slugs[ $index ] : $slug;
} );
```

## Notes

Only applies when the profile language is one of your Polylang languages; otherwise Polylang's normal detection runs.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Use Each User's Profile Language as Their Polylang Language" 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/
