默认的语言选择器是非常糟糕的TBH。
我使用jQuery创建了这个函数,您需要修改以适应您的模板。
function language_selector(){
$languages = icl_get_languages(\'skip_missing=0&orderby=code\');
$current_lang = ICL_LANGUAGE_CODE;
if(!empty($languages)) { ?>
<div id="language_list">
<div class="current">
<img src="<?php bloginfo(\'url\'); ?>/wp-content/plugins/sitepress-multilingual-cms/res/flags/<?php echo ICL_LANGUAGE_CODE; ?>.png" alt="<?php echo ICL_LANGUAGE_NAME; ?>" /> <?php echo ICL_LANGUAGE_NAME; ?> <i class="icon-chevron-down"></i>
</div>
<ul>
<?php foreach($languages as $l): ?>
<?php if($l[\'active\']) continue; ?>
<li>
<a href="<?php echo $l[\'url\']; ?>"><img src="<?php echo $l[\'country_flag_url\']; ?>" alt="<?php echo $l[\'native_name\']; ?>" /> <?php echo $l[\'native_name\']; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<script type="text/javascript">
$(document).ready(function(){
var languageSelector = $(\'#header .additional .language\');
var currentLanguage = $(\'.current\', languageSelector);
var languagesSelection = $(\'ul\', languageSelector);
var toggleLanguageSelector = function() {
if( !languagesSelection.is(\':visible\') ) {
currentLanguage.addClass(\'active\');
languagesSelection.slideDown(300);
} else {
currentLanguage.removeClass(\'active\');
languagesSelection.hide();
}
};
currentLanguage.bind(\'click\', toggleLanguageSelector);
});
</script>
<?php
}
}
然后执行如下操作:
<div class="language">
<span><?php _e(\'Choose Language\', \'theme_text_domain\'); ?></span>
<?php language_selector(); ?>
</div>
试试这个,看看它是否有效,显然我会把CSS留给你。