qtranslate-xで言語切り替えリンクを作る

Pocket

<?php
$current_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>
<li class="lang-ja"><a href="<?php echo qtranxf_convertURL($current_url, 'ja', '', true);?>" hreflang="ja" title="日本語" class="qtranxs_image qtranxs_image_ja"><img src="<?php echo plugins_url('qtranslate-x'); ?>/flags/jp.png" alt="日本語" /><span style="display:none">日本語</span></a></li>
<li class="lang-en"><a href="<?php echo qtranxf_convertURL($current_url, 'en','',  true);?>" hreflang="en" title="English" class="qtranxs_image qtranxs_image_en"><img src="<?php echo plugins_url('qtranslate-x'); ?>/flags/us.png" alt="English" /><span style="display:none">English</span></a></li>

ミソは、 qtransxf_convertURL()の4つ目の引数。trueにすると、urlに言語を強制的に入れるから、ちゃんと言語が切り替わるようになる。

Comments on this post

No comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL