在wordpress网站中仅显示一种语言的文本

时间:2016-06-06 14:03:34

标签: php wordpress hide display wpml

我有一个使用WPML(法语和英语)的双语Wordpress网站。在我的页面simple.php之上,我有一个代码,发送一个以博客帖子标题为主题的电子邮件,一切正常,但是当我切换到英语(或回到法语)时,它仍然用法语写成和英语(显然)。

现在我的代码看起来像这样

...

    <div class="l-content">

        <?php do_action( 'us_before_single' ) ?>
            <section class="l-section">
                /* french */
                <div class="l-section-h i-cf" style="padding-bottom:0 !important; text-align:right;">
                <a href="mailto:contact@contact.com?subject=Demande d'information pour la formation <?php wp_title() ?>"><i class="fa fa-envelope-o" aria-hidden="true"></i> Plus d'informations &gt;</a>
                </div>

                /* english */
                <div class="l-section-h i-cf" style="padding-bottom:0 !important; text-align:right;">
                <a href="mailto:contact@contact.com?subject=More info request <?php wp_title() ?>"><i class="fa fa-envelope-o" aria-hidden="true"></i> Get more info &gt;</a>
                </div>
            </section>
        <?php

        while ( have_posts() ){
            the_post();

            us_load_template( 'templates/blog/single-post', $template_vars );
        }
        ?>

        <?php do_action( 'us_after_single' ) ?>

    </div>

...

我的问题是如何让它检测语言,只显示正确的语言,或隐藏其他语言?

1 个答案:

答案 0 :(得分:0)

使用WPML Constant ICL_LANGUAGE_CODE获取当前语言,并应用if条件仅打印所需的div