Lang Forge provides drop-in WPML compatibility functions so that themes and plugins built for WPML work without any code changes. These functions are only defined when WPML is not active, so there is no conflict if WPML is installed alongside Lang Forge (e.g., during a gradual migration).
The compatibility layer covers the most commonly used WPML API functions. If your theme or a third-party plugin calls any of these, it will work transparently with Lang Forge.
icl_get_languages($args)
Returns the same data structure that WPML themes expect, making it the most frequently used WPML compatibility function.
/**
* WPML-compatible: Get all languages with URLs and flag data.
*
* @param string|array $args Optional. 'skip_missing' => 0, 'orderby' => 'custom'
* @return array Associative array keyed by language code. Each entry contains:
* id, code, active, native_name, translated_name,
* language_code, country_flag_url, url
*/
$languages = icl_get_languages('skip_missing=0');
foreach ($languages as $lang) {
echo '<a href="' . esc_url($lang['url']) . '">';
echo '<img src="' . esc_url($lang['country_flag_url']) . '" alt="" width="20" height="14"> ';
echo esc_html($lang['native_name']);
echo '</a>';
}| Parameter | Type | Description | |
|---|---|---|---|
$args | string | array | Optional. Query string or array with skip_missing and orderby keys. |
| Return Type | Description |
|---|---|
array | Associative array keyed by language code with WPML-compatible fields |
[
'en' => [
'id' => 'en',
'code' => 'en',
'active' => 1, // 1 if current language, 0 otherwise
'native_name' => 'English',
'translated_name' => 'English',
'language_code' => 'en',
'country_flag_url' => 'https://example.com/wp-content/plugins/langforge/assets/flags/gb.svg',
'url' => 'https://example.com/en/',
],
// ...
]// This code from a WPML-compatible theme works unchanged:
$languages = icl_get_languages('skip_missing=0&orderby=custom');
if (!empty($languages)) {
echo '<div class="language-bar">';
foreach ($languages as $lang) {
$class = $lang['active'] ? 'current-lang' : '';
echo '<a href="' . esc_url($lang['url']) . '" class="' . $class . '">';
echo '<img src="' . esc_url($lang['country_flag_url']) . '" alt="' . esc_attr($lang['native_name']) . '"> ';
echo esc_html($lang['native_name']);
echo '</a> ';
}
echo '</div>';
}$languages = icl_get_languages('skip_missing=1');
// Only languages that have a translation for the current page are returned.
// On archive pages, all languages are returned since archives are dynamically filtered.icl_object_id($element_id, $element_type, $return_original, $language_code)
Returns the translated post/page ID for a given language. This is the most commonly used WPML function in theme code.
/**
* WPML-compatible: Get translated post ID.
*
* @param int $element_id Original post/page ID
* @param string $element_type 'post', 'page', or any post type slug
* @param bool $return_original Return original ID if no translation exists
* @param string|null $language_code Target language (default: current language)
* @return int|null Translated post ID
*/
// Get the French version of post #42
$french_id = icl_object_id(42, 'post', false, 'fr');
// Get the translation in the current language, or the original if none exists
$translated_id = icl_object_id(42, 'page', true);| Parameter | Type | Description | |
|---|---|---|---|
$element_id | int | Original post/page ID | |
$element_type | string | Post type slug: 'post', 'page', 'product', etc. | |
$return_original | bool | If true, returns the original ID when no translation exists. If false, returns null. | |
$language_code | string | null | Target language code. Defaults to the current language. |
| Return Type | Description | |
|---|---|---|
int | null | Translated post ID, or null (or original ID if $return_original is true) |
// This code from a WPML theme works unchanged with Lang Forge:
$page_id = icl_object_id(get_option('page_on_front'), 'page', true);
$home_url = get_permalink($page_id);
echo '<a href="' . esc_url($home_url) . '">Home</a>';// Get all translations of key pages
$pages = [
'about' => 10,
'contact' => 15,
'faq' => 22,
];
$languages = lf_get_languages();
$page_map = [];
foreach ($pages as $slug => $id) {
foreach ($languages as $code => $lang) {
$translated_id = icl_object_id($id, 'page', false, $code);
if ($translated_id) {
$page_map[$slug][$code] = $translated_id;
}
}
}
// $page_map = ['about' => ['ru' => 10, 'en' => 45], 'contact' => ['ru' => 15, 'en' => 46], ...]icl_get_current_language() / icl_get_default_language()
/**
* WPML-compatible: Get current language code.
* @return string Current language code
*/
$lang = icl_get_current_language();
/**
* WPML-compatible: Get default language code.
* @return string Default language code
*/
$default = icl_get_default_language();icl_language_selector action
Themes that use WPML’s do_action('icl_language_selector') will automatically get Lang Forge’s switcher:
// In a theme template - this works with both WPML and Lang Forge
do_action('icl_language_selector');> Note: The WPML compatibility layer maps directly to Lang Forge’s native functions. There is no performance penalty for using WPML functions.
—