Action hook 'switch_locale'

in WP Core File wp-includes/class-wp-locale-switcher.php at line 98

View Source

switch_locale

Action Hook
Description
Fires when the locale is switched.

Hook Information

File Location wp-includes/class-wp-locale-switcher.php View on GitHub
Hook Type Action
Line Number 98

Hook Parameters

Type Name Description
string $locale The new locale.
false|int $user_id User ID for context if available.

Usage Examples

Basic Usage
<?php
// Hook into switch_locale
add_action('switch_locale', 'my_custom_function', 10, 2);

function my_custom_function($locale, $user_id) {
    // Your custom code here
}

Source Code Context

wp-includes/class-wp-locale-switcher.php:98 - How this hook is used in WordPress core
<?php
  93  		 * @since 6.2.0 The `$user_id` parameter was added.
  94  		 *
  95  		 * @param string    $locale  The new locale.
  96  		 * @param false|int $user_id User ID for context if available.
  97  		 */
  98  		do_action( 'switch_locale', $locale, $user_id );
  99  
 100  		return true;
 101  	}
 102  
 103  	/**

PHP Documentation

<?php
/**
		 * Fires when the locale is switched.
		 *
		 * @since 4.7.0
		 * @since 6.2.0 The `$user_id` parameter was added.
		 *
		 * @param string    $locale  The new locale.
		 * @param false|int $user_id User ID for context if available.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 2
  • File: wp-includes/class-wp-locale-switcher.php
Related Hooks

Related hooks will be displayed here in future updates.