Un projet web multilingue en collaboration avec Richard Picard d’Affluences pour le SEO.
Site web : limoquebec.com

Un autre excellent projet de refonte web pour le Groupe Limo Québec, incluant la refonte visuel de l’intégration du formulaire LimoAnywhere. Le design incluait une refonte des icônes afin de mieux identifier les services, des couleurs plus vives tout en conservant le côté noble et professionnel par le choix de typographie.

Nous avons choisi d’intégrer Cloudflare Turnstile pour l’anti-robot des formulaires personnalisés, le tout dans un thème enfant de Divi.

Fonction personnalisé pour le sélecteur langue WPML

C’est également dans ce projet que j’ai bonifié un peu mon « injection » du sélecteur de langue de WPML dans le menu primaire. J’avais besoin de pouvoir faire afficher mon sélecteur a un endroit plus précis – dans ce cas, avant des boutons de contact. J’ai donc ajouté une fonctionnalité dans le thème enfant qui recherche la class CSS « nickolabs_lang_switcher » afin de remplacer cette élément.

Voici le code actuel si jamais vous souhaitez en bénéficier ou le mettre à votre main – il y a sûrement des optimisation à y faire alors faites le moi savoir!

/**
 * Added in the functions.php of the Child-theme
 * ADDING LANGUAGE TO MAIN MENU
 * You can add the menu to a SPECIFIC location by having a menu item
 * such as a Custom link with the classname : nickolabs_lang_switcher
 * The script will search for "li.nickolabs_lang_switcher" in the HTML.
 */
add_filter( 'wp_nav_menu_items', 'add_wpml_langs_to_nav_menu', 10, 2 );
function add_wpml_langs_to_nav_menu( $items, $args ) {
    if( $args->theme_location == 'primary-menu' ){
        if (function_exists('icl_get_languages')) {
            $languages = icl_get_languages('skip_missing=0');
            if(1 < count($languages)){
                // There more then one language, therefore find where to inject our custom menu item
                // Prepare DOMObject for proper searching of out target classname : nickolabs_lang_switcher
                $htmlmenu = new DOMDocument();
                $convertedhtml = mb_convert_encoding($items, 'HTML-ENTITIES', "UTF-8");
                $htmlmenu->loadHTML($convertedhtml);
                $finder = new DomXPath($htmlmenu);
                // Target classname
                $classname = "nickolabs_lang_switcher";
                $founditemnodes = $finder->query("//li[contains(@class, '$classname')]");
                $tmp_dom = new DOMDocument(); 
                // Set our flag for our fallback method
                $tobereplacedinnerHTML = false;
                if (!empty($founditemnodes[0])) {
                    // Target Classname was found, extract the HTML for the str_replace or $items
                    $tmp_dom->appendChild($tmp_dom->importNode($founditemnodes[0],true));
                    $tobereplacedinnerHTML = trim($tmp_dom->saveHTML());
                }
                foreach($languages as $l){
                    $active_lang = "";
                    // Get a proper "Switch to" string
                    if ($l['language_code'] == 'fr') {
                        $lang_switch_string = "Visiter le site en ".$l['native_name'];
                    } else {
                        $lang_switch_string = "View website in ".$l['native_name'];
                    }
                    if ($l['active']) {
                        $active_lang = " active_lang";
                    } else {
                        // Only display the link if it isn't the current language
                        
                        // Short version with flag
                        $newitemHTML .='<li class="menu-item lang-switcher">
                            <a href="'.$l['url'].'" title="'.$lang_switch_string.'" class="language'.$active_lang.'">
                            <img src="'.$l['country_flag_url'].'"> '.$l['language_code'].'</a>
                        </li>';

                        // Short version with Abbreviation for Mobile
                        //$newitemHTML .='<li><a href="'.$l['url'].'" title="'.$lang_switch_string.'" class="language'.$active_lang.'">'.$l['language_code'].'</a></li>';

                        // Full version with Full language name
                        // $newitemHTML .='<li class="menu-item lang-switcher">
                        //     <a href="'.$l['url'].'" title="'.$lang_switch_string.'" class="language'.$active_lang.'">'.$l['native_name'].'</a>
                        // </li>';
                    }
                    // Display all possible languages
                    //$newitemHTML .= '<li><a href="'.$l['url'].'" title="'.$lang_switch_string.'" class="language'.$active_lang.'">'.$l['language_code'].'</a></li>';
                }
                // Inject the Lang Switcher in the menu, either by adding to, or replacing our target
                if ($tobereplacedinnerHTML == false) {
                    // Target classname wasn't found so fallback to injecting the item anyway
                    $items .= $newitemHTML;
                } else {
                    // Target classname was found so replace  the item
                    $items = str_replace($tobereplacedinnerHTML, $newitemHTML, $items);
                }
            }
        }
    }
    return $items;
}

Pin It on Pinterest

Share This