WordPress filter hook

wpml_locale

Fired by 8 WordPress plugins, running on 21K+ sites between them.

“Filters the locale for a language code. Provided by WPML.”

How to use wpml_locale

It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'wpml_locale', function( $value, $lang ) {
	// Change $value here.
	return $value;
}, 10, 2 );

Argument names come from Payment Gateway for PayPal on WooCommerce's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

8 plugins that fire wpml_locale

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Echo Knowledge Base icon Echo Knowledge Base10,000+ installs apply_filters( 'wpml_locale', get_locale(), $wpml_lang ) includes/system/class-epkb-language-utilities.php:20
  2. Payment Gateway for PayPal on WooCommerce icon Payment Gateway for PayPal on WooCommerce10,000+ installs apply_filters( 'wpml_locale', null, $lang ) ppcp/public/class-ppcp-paypal-checkout-for-woocommerce-button-manager.php:4538
  3. Listdom: AI-powered Business Directory with Classifieds Ads Listings icon Listdom: AI-powered Business Directory with Classifieds Ads Listings1,000+ installs apply_filters( 'wpml_locale', '', $lang ) app/includes/labels.php:75
  4. Recovero icon Recovero50+ installs apply_filters( 'wpml_locale', '', $language ) includes/core/class-ppl-acrw-i18n.php:259
  5. Cart Sharing and Saving For WooCommerce icon Cart Sharing and Saving For WooCommerceFewer than 10 installs apply_filters( 'wpml_locale', null, $_default_lang ) class-lang.php:54
  6. LAFU Gift Cards icon LAFU Gift CardsFewer than 10 installs apply_filters( 'wpml_locale', null, $lang ) includes/class-lafu-gift-cards-i18n.php:136
  7. Baza Booking Calendar icon Baza Booking CalendarFewer than 10 installs apply_filters( 'wpml_locale', null ) modules/translations/traits/trait-data.php:68
  8. RM24 Swiss Invoices & Delivery Notes for WooCommerce icon RM24 Swiss Invoices & Delivery Notes for WooCommerceFewer than 10 installs apply_filters( 'wpml_locale', '', $lang ) includes/class-rm24-sid-renderer.php:151

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.