How to: A multilingual navigation menu


Navigation Menu is a theme feature introduced with Version 3.0. WordPress includes an easy to use mechanism for introducing customized navigation menus into a theme.
The dashboard interface has made great progress for users (and newbies) from version to version.
Inside a theme, a navigation menu appears at a location, currently near the header. A menu has a structure made with menu items to redirect to webpage containing (as WordPress describes them) a static page, a list of posts in a category, of a target date, or resulting of a query…
In dashboard side, we find in “appearance/menu” page, the location settings and how to set the menu with his structure.
Note: A menu structure can be attached to a widget.

In multilingual context on a standalone WordPress install,
for developers, it is possible to create a virtual location for each language (as presented in child theme Twentyfourteen-xili or other previous embedded (bundled) themes of WP install).

A menu location contains
   one menu structure with
      various menus items.

But there are (huge) thousand of themes (free or commercial) following or not following the codex rules of development.

Since 5 years, on the long way to work in the thousands of lines of WP source, it was recently possible to use powerful pieces of code to create menu item like insertion points replaced by navigation list elements.

A multilingual navigation menu with xili-language with menus insertion point.

In the content strategy of the example, we decide that the contents of menu are not similar in each language.
First step: a menu (structure) per language
These structures should not be attached to a location to remain free to be used by menus insertion point.
Second step: a core menu attached to the menu location of the theme.
Third step: a menus insertion point and a language list insertion point inside the core menu.

Limitation: a menu structure associated to an insertion point must not contains another insertion points.

Some screenshots:

English menu w/o location

English menu w/o location

Menus Insertion item

Menus Insertion item before adding to structure

Core menu after insertion

Core menu after insertion


Plugin JetPack: what about with class Featured_Content from theme TwentyFourteen ?

Plugin JetPack has a strange behavior with class Featured_content of TwentyFourteen theme and child theme like here TwentyFourteen-xili!

Feedback after investigations

In TwentyFourteen, in sub-folder inc file featured-content.php contains class Featured_Content. It is possible to copy (and modify) inside child theme (as done in TwentyFourteen-xili to include sub-selection and cache according current language). As here in frontpage, only featured posts in a language are displayed. Because functions from functions.php are fired before those of parent theme: no problem, modified class has priority!

All is working well until JetPack will be installed… no sub-selection :-(
By tracing, the modified class is not used
In JetPack settings, no way to disable (not load) Featured_Content Class, only a class with same name loaded before is possible !
How to force to download the child theme Featured_Content Class ?

In sources below (theme-tools.php – extrait ci-dessous) : no filter, only test with class_exists

// Featured Content has an internal check for theme support in the constructor.
// This could already be defined by Twenty Fourteen if it's loaded first.
// Be sure to not load this on the plugin page in case another plugin is activating
// with the same class name in an attempt to override Jetpack's Featured_Content
if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { 
    require_once( JETPACK__PLUGIN_DIR . 'modules/theme-tools/featured-content.php' );

Only possible solution, creating a plugin with a filter before the time where JetPack load the modules (plugins_loaded – priority 100).

Remember it is impossible to add filters “plugins_loaded” inside functions.php of a theme. It is too late according timeline of wp_settings.

The code below show that featured-content.php file will be required before JetPack requires its modules:

function xili_jetpack_disable_featured () {
    if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
        if ( file_exists( get_stylesheet_directory() . '/inc/featured-content.php' ) ) {
            require get_stylesheet_directory() . '/inc/featured-content.php'; // this one will disable others
if ( class_exists ( 'jetpack' ) ) { // inited by init filter but without modules (priority 100 in jetpack)
    add_action( 'plugins_loaded', 'xili_jetpack_disable_featured', 17 ); // after XL and XTT

This example code lines are easy to insert in a very simple plugin.
For multilingual context, these lines (with options) are now inside xili-language (v 2.11.1+). Here, you will see in real time that TwentyFourteen-xili multilingual recovers his behavior and sub-select featured posts in frontpage.


xili-language settings

xili-language version 2.11 shipped

Latest release (2.11) of xili-language shipped today.

Some new things for theme’s developers:

A conditional function – is_xili_curlang():
* Test the current language of displayed page.
* @since 2.11
* use for other function elsewhere
* @param "" for undefined, slug of tested language alone or an array list
* @return true or false
function is_xili_curlang( $lang = false ) {

This function is also usable in plugin xili-postinpost widget.

The oldest function of xili-language – the_curlang() – is improved and now is able to return the desired property of current language. Useful for choosing condition of part display according language.
* Return the current language of theme.
* @since 0.9.7
* @updated 2.11.0
* use by other function elsewhere
* @param slug, iso, full name, alias, charset, hidden, count
* @return by default the slug of language (used in query).
function the_curlang( $by = 'slug' ) { // soon obsolete
return xili_curlang( $by );
function xili_curlang( $by = 'slug' ) {

More available preset languages in list:

Now using list provided by jetpack, an almost complete list of languages is available with english name, native name and more…
In the list, if the native name is followed by a *, the language is not associated with wp_locale (an official language managed by WP.)

xili-dictionary version 2.6 shipped

xili-dictionary extension is shipped (2.6) and include now plugin language file management.
With taxonomy “Origin”, msgid and msgstr are assigned to the target plugin and it is easy to import terms in dictionary and to create, update language files of the target plugin.

xili-dictionary analyse header of plugin’s sources and this two items ‘Text Domain’ and ‘Domain Path’. If author omits to define them, xili-dictionary try to specify them according language files yet available in plugin’s folder.