Tagged: wpml
-
AuthorPosts
-
April 16, 2019 at 1:25 pm #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?
April 17, 2019 at 10:27 am #1091892Anybody from support with the solution?
April 17, 2019 at 11:58 pm #1092175Hi,
Have you tried contact WPML team for a solution? They would be more easy to help on this issue.
Best regards,
BasilisApril 18, 2019 at 2:35 pm #1092439Yes 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.
April 19, 2019 at 2:43 pm #1092688Hi,
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ünterApril 19, 2019 at 2:58 pm #1092692Hi,
You can also replace enfold/config-wpml/config.php (Enfold 4.5.6) with
Best regards,
GünterApril 22, 2019 at 8:06 pm #1093398Hi Gunter,
I’ve tried both options, but both did not work.
April 23, 2019 at 9:09 am #1093578Hi,
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ünterApril 23, 2019 at 9:52 am #1093592Hi 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;
});April 23, 2019 at 2:22 pm #1093670Hi,
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ünterApril 24, 2019 at 9:19 am #1093895Hi Gunter,
Thanks for you help (and your patience :-) ) This code works!!
Thanks a lotBR
jeffApril 24, 2019 at 9:42 am #1093899 -
AuthorPosts
- The topic ‘WPML link one flag to different domain’ is closed to new replies.