Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Dante › Polylang plugin integration
New Landing › How can we help? › Themeforest Theme Support › Dante › Polylang plugin integration
- This topic has 4 replies, 4 voices, and was last updated 10 years by
Kyle – SUPPORT.
-
Posted in: Dante
-
January 4, 2015 at 3:10 pm #138841
Hi!
This is not a request for help, but I thought I’d rather share my experience in integrating Polylang langauge plugin with Dante.
I have already posted a request for small modification in the source code of the parent theme here: …/dante-feature-request/page/21/#post-138835
In order to make this work, I used child theme’s
functions.php
and have overriden the originalsf_language_flags()
function (I had to change the function’s definition to conditional in the parent theme).So below is my code for the new
sf_language_flags()
, which also incorporates the original code:if (!function_exists('sf_language_flags')){ function sf_language_flags() { $language_output = ""; if (function_exists('pll_the_languages')){ $languages = pll_the_languages(array('raw'=>1)); if(!empty($languages)){ foreach($languages as $l){ $language_output .= '<li>'; if($l['flag']){ if(!$l['current_lang']) { $language_output .= '<a href="'.$l['url'].'"><img src="'.$l['flag'].'" height="12" alt="'.$l['slug'].'" width="18" /><span class="language name">'.$l['name'].'</span></a>'."\n"; } else { $language_output .= '<div class="current-language"><img src="'.$l['flag'].'" height="12" alt="'.$l['slug'].'" width="18" /><span class="language name">'.$l['name'].'</span></div>'."\n"; } } $language_output .= '</li>'; } } } elseif (function_exists('icl_get_languages')) { $languages = icl_get_languages('skip_missing=0&orderby=code'); if(!empty($languages)){ foreach($languages as $l){ $language_output .= '<li>'; if($l['country_flag_url']){ if(!$l['active']) { $language_output .= '<a href="'.$l['url'].'"><img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" /><span class="language name">'.$l['translated_name'].'</span></a>'."\n"; } else { $language_output .= '<div class="current-language"><img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" /><span class="language name">'.$l['translated_name'].'</span></div>'."\n"; } } $language_output .= '</li>'; } } } else { $flags_url = get_template_directory_uri() . '/images/flags'; $language_output .= '<li><a href="#">DEMO - EXAMPLE PURPOSES</a></li><li><a href="#"><span class="language name">German</span></a></li><li><div class="current-language"><span class="language name">English</span></div></li><li><a href="#"><span class="language name">Spanish</span></a></li><li><a href="#"><span class="language name">French</span></a></li>'."\n"; } return $language_output; } }
Note the order, I noticed that somehow (how?!) when I installed Polylang, it still could call the WPML’s function
icl_get_languages
and even get some data out of it! Such as urls and flag images…I hope you will find this helpful.
January 5, 2015 at 11:33 am #138966Hi,
Thanks for your contribution.
Will forward it to the development team.-Rui
January 6, 2015 at 1:49 am #139193Thanks for the code! Will include that for the next update.
– Ed
January 6, 2015 at 11:46 am #139339Hi! Thanks for the feedback. I just wanted to mention, that this thing only works for the normal menu, I didn’t change anything in the mobile menu, since, as I mentioned earlier, existing code is able to get the flags and links from the Polylang somehow…
January 6, 2015 at 12:28 pm #139349Ok thanks
-
Posted in: Dante
You must be logged in and have valid license to reply to this topic.