Skip to content

Template tags

These are deliberately plain global functions, not methods on some container a template has to know how to reach. Call any of them from a classic theme’s functions.php or a template file.

localeeasy_switcher( array $options = [] )

Section titled “localeeasy_switcher( array $options = [] )”

Print the language switcher. Drop it anywhere in a theme template:

<?php localeeasy_switcher(); ?>

Pass any of the switcher’s options to override the site default for this one placement — the same options the shortcode and the block accept:

<?php localeeasy_switcher( [ 'layout' => 'dropdown', 'labelStyle' => 'both' ] ); ?>

localeeasy_get_switcher( array $options = [] ): string

Section titled “localeeasy_get_switcher( array $options = [] ): string”

The same markup as localeeasy_switcher(), returned instead of printed.

Section titled “localeeasy_get_language_links( ?string $label_style = null ): array”

The raw language links for the current request — locale, URL, whether it is the current language, and both a plain and an HTML-escaped label — with none of the switcher’s wrapping markup. Use this to build a completely custom switcher, in PHP or handed to JavaScript as data.

foreach ( localeeasy_get_language_links() as $link ) {
printf(
'<a href="%s" hreflang="%s"%s>%s</a>',
esc_url( $link['url'] ),
esc_attr( $link['lang'] ),
$link['current'] ? ' aria-current="true"' : '',
$link['label_html']
);
}

The locale this request is being read in, taken from the URL. Returns the site’s own source locale on an untranslated request, so a template can use the return value without checking anything first.

The locale the visitor is actually reading in, even on a request with no locale prefix of its own — a form handler, an AJAX endpoint, a REST route. Looks at the page the request came from and the language a visitor already chose. Returns an empty string when the visitor is reading the site in its own source language.

localeeasy_remember_locale( int $object_id, string $locale = '' )

Section titled “localeeasy_remember_locale( int $object_id, string $locale = '' )”

Note which language an object — an order, a booking, a support ticket — was created in, while the visitor who created it is still on the site. An empty locale remembers the visitor’s own current one. This is the same mechanism LocaleReady’s WooCommerce and Gravity Forms support use.

localeeasy_remembered_locale( int $object_id ): string

Section titled “localeeasy_remembered_locale( int $object_id ): string”

The language noted by localeeasy_remember_locale(), read back whenever the object’s email actually goes out — which can be minutes or months later, from a request with no idea what language the original visitor read in.

localeeasy_mail_locale( string $locale, callable $work )

Section titled “localeeasy_mail_locale( string $locale, callable $work )”

Run a block of code with every email it sends going out in one language:

localeeasy_mail_locale(
localeeasy_remembered_locale( $order_id ),
static fn() => $order->send_shipping_notification()
);

An empty or no-longer-available locale runs $work with nothing changed, so a caller never has to check first.