Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #521207

    Hi there,

    I have two issues concerning the compatibility with WPML:

    1) I’d like to reposition the flag in the menu so that it appears between the Shop button and the social media buttons. I added it via the child function.php. I’d also like to get it down a few pixels.
    http://test.entspannt.de

    2) The links between the different language versions works fine for the pages but not with the portfolio items. For example…
    http://test.entspannt.de/portfolio-item/deine-familie/?lang=en

    #521441

    Hey entspannt!

    Thank you for using Enfold.

    1.) How did you add the language flags? Did you remove the theme’s default language switcher? If you want to use the default WPML switcher options, add this in the functions.php file then configure the switcher options in the WPML panel:

    add_action('after_setup_theme','avia_remove_main_menu_flags');
    function avia_remove_main_menu_flags(){
            remove_filter( 'wp_nav_menu_items', 'avia_append_lang_flags', 20, 2 );
            remove_filter( 'avf_fallback_menu_items', 'avia_append_lang_flags', 20, 2 );
            remove_action( 'avia_meta_header', 'avia_wpml_language_switch', 10);
    }

    2.) Flush the Settings > Permalink options. I don’t see any issue when I check the portfolio item: http://test.entspannt.de/portfolio-item/deine-familie/?lang=en

    Best regards,
    Ismael

    #526555

    Hi Ismael,

    I solved the issue using your code together with one provided by WPML, see the code below.

    Thanks for your help!

    All the best,
    Steffen

    <?php
    
    /*
    * Add your own functions here. You can also copy some of the theme functions into this file. 
    * WordPress will use those functions instead of the original functions then.
    */
    
    add_action('after_setup_theme','avia_remove_main_menu_flags');
    function avia_remove_main_menu_flags(){
            remove_filter( 'wp_nav_menu_items', 'avia_append_lang_flags', 20, 2 );
            remove_filter( 'avf_fallback_menu_items', 'avia_append_lang_flags', 20, 2 );
            remove_action( 'avia_meta_header', 'avia_wpml_language_switch', 10);
    }
    
    // Filter wp_nav_menu() to add additional links and other output
    // Show only other language in language switcher
    add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
    function new_nav_menu_items($items, $args) {
        // uncomment this to find your theme's menu location
        //echo "args: <pre>"; print_r($args); echo "</pre>";
         
        // add $args->theme_location == 'primary-menu' in the conditional if we want to specify the menu location.
        // if (function_exists('icl_get_languages') && $args->theme_location == 'avia') {
        if (function_exists('icl_get_languages')) {
            $languages = icl_get_languages('skip_missing=0');
     
            if(!empty($languages)){
     
                foreach($languages as $l){
                    if(!$l['active']){
                        // flag with native name
                        //$items = $items . '<li class="menu-item"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /> ' . $l['native_name'] . '</a></li>';
                        // only flag
                        $items = $items . '<li class="menu-item menu-item-language"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /></a></li>';
                    }
                }
            }
        }
         
        return $items;
    }
    #526933

    Hey!

    Glad you figured it out and thank you for sharing your solution! :)

    Regards,
    Yigit

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘WPML language switcher doesn't work, repositioning of flag’ is closed to new replies.