Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1091415

    Hi guys,

    I’ve setup wpml, which works fine with the theme. BUT I need to link one flag/language to a seperate domain. It’s the Czech flag. I’ve added this code to the functions.php in the theme folder.

    add_filter( ‘icl_ls_languages’, function( $languages ) {
    $languages[‘cs][‘url’] = ‘theurltolinkto’;
    return $languages;
    });

    But it does not link. You first go to .com/cs and only than when you click on the Czech flag the link works. According to the guys from wpml is has to do with the is_home in the config.php in the config-wpml folder (sentence 276)

    What/how to change so the CS flag links directly to the different domain?

    #1091892

    Anybody from support with the solution?

    #1092175

    Hi,

    Have you tried contact WPML team for a solution? They would be more easy to help on this issue.

    Best regards,
    Basilis

    #1092439

    Yes I did > see their reply

    By the code of your theme, Enfold is changing the URL of the homepage and so this problem is happening.
    This is happening in the file “enfold/config-wpml/config.php” at line 276. Your theme is forcing the default URL on the homepage:
    1
    if(!avia_is_overview() && (is_home() || is_front_page())) $lang[‘url’] = $sitepress->language_url($lang[‘language_code’]);
    I did not find any filters to disable this or change the behavior of your theme. In this case, I should recommend that you contact the author of your theme so that they can check this out.

    You may need to remove these codes from your theme and use the native WPML selector. Or you can create a child theme to try to filter this URL.

    #1092688

    Hi,

    In my opinion WPML could add a filter to their function SitePress::language_url.

    Nevertheless we will add a filter:

    In the file “enfold/config-wpml/config.php” at line 276:

    
    if(!avia_is_overview() && (is_home() || is_front_page())) $lang['url'] = $sitepress->language_url($lang['language_code']);
    

    replace with:

    
    					if( ! avia_is_overview() && ( is_home() || is_front_page() ) )
    					{
    						$url = $sitepress->language_url( $lang['language_code'] );
    						
    						/**
    						 * @since 4.5.6.1
    						 * @return string
    						 */
    						$lang['url'] = apply_filters( 'avf_wpml_language_switcher_url', $url, $lang['language_code'], $avia_config['wpml_language_menu_position'] );
    					}
    

    and in line 596:

    
    if(is_front_page()) $lang['url'] = $sitepress->language_url($lang['language_code']);
    

    replace with

    
    						if( is_front_page() )
    						{
    							$url = $sitepress->language_url( $lang['language_code'] );
    						
    							/**
    							 * @since 4.5.6.1
    							 * @return string
    							 */
    							$lang['url'] = apply_filters( 'avf_wpml_language_switcher_url', $url, $lang['language_code'], $avia_config['wpml_language_menu_position'] );
    						}
    

    I will add these filters to our dev repo.

    Best regards,
    Günter

    #1092692

    Hi,

    You can also replace enfold/config-wpml/config.php (Enfold 4.5.6) with

    https://github.com/KriesiMedia/enfold-library/blob/master/temp_fixes/Enfold_4_5_6/WPML_filters/config.php

    Best regards,
    Günter

    #1093398

    Hi Gunter,

    I’ve tried both options, but both did not work.

    #1093578

    Hi,

    Did you add a filter function

    
    add_filter( 'avf_wpml_language_switcher_url', ...... )
    

    and clear server and browser cache (you also might to save theme options in case you are using enfold compression).

    Best regards,
    Günter

    #1093592

    Hi Gunter,

    What code/ filter do I have to add exactly? Currently I added this to the functions.php in the themes/enfold/functions.php

    add_filter( ‘icl_ls_languages’, function( $languages ) {
    $languages[‘cs][‘url’] = ‘theurltolinkto’;
    return $languages;
    });

    #1093670

    Hi,

    OK. Then there cannot be any change. As you can see in https://kriesi.at/support/topic/wpml-link-one-flag-to-different-domain/#post-1092688 I added filter avf_wpml_language_switcher_url to modify the urls specific for the menus (as WPML does not provide a filter).

    You can use the following as a basis for your code (https://github.com/KriesiMedia/enfold-library/blob/master/actions%20and%20filters/WPML/avf_wpml_language_switcher_url.php):

    
    /**
     * Filter the URL in language switcher flags
     * 
     * @since 4.5.6.1
     * @param string $url
     * @param string $lang_code
     * @param string $menu_position				'sub_menu' | 'main_menu'
     * @return string
     */
    function my_wpml_language_switcher_url( $url, $lang_code, $menu_position )
    {
    	if( $lang_code == 'cs' )
    	{
    		$url = 'your_url';
    	}
    	
    	return $url;
    }
    
    add_filter( 'avf_wpml_language_switcher_url', 'my_wpml_language_switcher_url', 10, 3 );
    
    

    Best regards,
    Günter

    #1093895

    Hi Gunter,

    Thanks for you help (and your patience :-) ) This code works!!
    Thanks a lot

    BR
    jeff

    #1093899

    Hi,

    Glad we could help you.

    Enjoy the theme and feel free to come back if you need further assistance.

    Best regards,
    Günter

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘WPML link one flag to different domain’ is closed to new replies.