Title: switch_locale
Published: December 6, 2016
Last modified: May 20, 2026

---

# do_action( ‘switch_locale’, string $locale, false|int $user_id )

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/hooks/switch_locale/?output_format=md#wp--skip-link--target)

Fires when the locale is switched.

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

 `$locale`string

The new locale.

`$user_id`false|int

User ID for context if available.

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

    ```php
    do_action( 'switch_locale', $locale, $user_id );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-locale-switcher.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-locale-switcher.php#L98)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-locale-switcher.php#L98-L98)

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

| Used by | Description | 
| [WP_Locale_Switcher::switch_to_locale()](https://developer.wordpress.org/reference/classes/wp_locale_switcher/switch_to_locale/)`wp-includes/class-wp-locale-switcher.php` |

Switches the translations according to the given locale.

  |

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

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | The `$user_id` parameter was added. | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/switch_locale/?output_format=md#comment-content-6528)
 2.   [Harsh Gajipara](https://profiles.wordpress.org/harshgajipara/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/switch_locale/#comment-6528)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_locale%2F%23comment-6528)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_locale%2F%23comment-6528)
 4. Basic example of the hook for below operations.
 5.  a. Updating the user meta with the new locale using the [update_user_meta()](https://developer.wordpress.org/reference/functions/update_user_meta/)
        function.
     b. Displaying a success message indicating the switched locale.
 6.     ```php
        // Define a callback function to execute when the switch_locale action is triggered
        function wpdocs_switch_locale_callback( $locale, $user_id ) {
            // Perform custom logic or tasks here based on the locale and user ID
    
            // Example: Update user meta with the new locale
            update_user_meta( $user_id, 'locale', $locale );
    
            // Example: Display a success message
            echo 'Locale switched to: ' . $locale;
        }
    
        // Hook the callback function to the switch_locale action
        add_action( 'switch_locale', 'wpdocs_switch_locale_callback', 10, 2 );
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_locale%2F%3Freplytocom%3D6528%23feedback-editor-6528)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_locale%2F)
before being able to contribute a note or feedback.