I'm trying to make one-button language switch using qtranslate and different url mydomain.com/en/ etc. ), but with PHP I'm unable to do that, since it takes just a first (loading document) state.

<div class="language-box">
<?php if (get_locale() == 'en_EN') { ?>
<a href="/en/" class="lang en">
<img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-czech.png"/>
<?php } else { ?>
<a href="/cs" class="lang cz">
<img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-english.png"/> 
<?php } ?>
</a>
</div> 
有帮助吗?

解决方案

<?php

$lang = get_locale();
$href = "cz";
$img = "english";

switch ($lang){
    case "en_EN":
        $href = "en";
        $img = "czech";
        break;     
    default:
        $href = "cz";
        $img = "english";
        break;
}

?>

<div class="language-box">
    <a href="/<?php echo $href; ?>/" class="lang <?php echo $href; ?>">
        <img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-<?php echo $img; ?>.png"/>
    </a>
</div>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top