-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnnipet.php
54 lines (44 loc) · 1.94 KB
/
snnipet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//Function to show a funcion dropdown of active lenguajes whit the [custom_wpml_language_dropdown] shortcode
function custom_wpml_language_dropdown() {
ob_start();
?>
<div class="custom-language-dropdown">
<select onchange="if (this.value) window.location.href=this.value">
<?php
$languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' );
foreach ($languages as $code => $language) {
$selected = ($code == ICL_LANGUAGE_CODE) ? 'selected="selected"' : '';
echo '<option value="' . $language['url'] . '" ' . $selected . '>' . $language['native_name'] . '</option>';
}
?>
</select>
</div>
<?php
return ob_get_clean();
}
add_shortcode('custom_wpml_language_dropdown', 'custom_wpml_language_dropdown');
// //Function to show a HORIZONTAL CUSTOM LIST
function custom_horizontal_language_list() {
$languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' );
if (!empty($languages)) {
$output = '<div class="custom-horizontal-language-list">';
$total_languages = count($languages);
$current = 1;
foreach ($languages as $code => $language) {
// idioma es el actual en negrita
if ($language['active']) {
$output .= '<strong>' . strtoupper($language['language_code']) . '</strong>';
} else {
$output .= '<a href="' . $language['url'] . '">' . strtoupper($language['language_code']) . '</a>';
}
// Agregar el separador "|" si no es el último idioma
if ($current < $total_languages) {
$output .= ' | ';
}
$current++;
}
$output .= '</div>';
return $output;
}
}
add_shortcode('custom_horizontal_language_list', 'custom_horizontal_language_list');