One little-known and little-used feature of Hybrid Core is called the “locale functions file.” In the past, this was a pretty standard file for most themes to include. Like many other features, it has fallen out of use. However, that doesn’t mean it isn’t useful to many users.
A locale functions file is a functions file (just like your theme’s
functions.php) that is designed for a specific locale. It’s pretty useful if you want to define functionality, for example, for U.S. English speakers.
What is a locale?
A locale in software terminology is the combination of a language, region, and possibly other identifiers. Generally, in WordPress, this is defined as
language_region. By default, WordPress is set up for the
en_US locale, which is U.S. English.
You can define your locale in WordPress’
wp-config.php file. For example, my locale is defined as the following.
define( 'WP_LANG', 'en_US' );
Read WordPress In Your Language for more information on this particular topic.
Using a locale functions file
Now that you know what a locale is, you can create your own locale-specific functions file. This file will only be loaded when a theme user is using the language defined by the locale. So, on my site, a
en_US.php file would be loaded but a
fr_FR.php (French) file would not be loaded.
The following list provides a few rules locale functions files must follow.
- All locale functions files must be within the parent or child theme’s
- You can create as many files as you want based on any number of languages.
- The earliest hook you can use in the file is
So, if I wanted to create a
en_US.php file for my site, the directory would look like the following:
my-theme /languages /en_US.php
That’s really all there is to it. It behaves just like any other theme functions file. You can add whatever code you want in it.