Title: Get Current Language Code Function/Method
Last modified: August 22, 2016

---

# Get Current Language Code Function/Method

 *  Resolved [Austeroid](https://wordpress.org/support/users/austeroid/)
 * (@austeroid)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/)
 * Hi,
 * I have the following code in my front-page.php file
 *     ```
       <section class="hero home">
                       <h1>Only show if selected language is EN</h1>
                       <h1>Only show if selected language is DE</h1>
                </section>
       ```
   
 * I would like to have the correct heading shown on the page according to the selected
   language. Is there any function that retrieves the language code so that I can
   create a conditional if else statement? For ex, something like:
 *     ```
       <section>
                       <? if(get_language_code()=='EN'): ?>
                             <h1>Only show if selected language is English</h1>
                       <? elseif(get_language_code()=='DE'): ?>
                             <h1>Only show if selected language is Deutsch</h1>
                       <? endif; ?>
                   </section>
       ```
   
 * I found [this article](http://www.openscriptsolution.com/cms/wordpress/how-to-get-current-language-code-by-using-qtranslate-plugin-of-wordpress/)
   and tried the suggested function but that doesn’t work for this plugin.
 * I can’t find an API so please help?
 * Regards,
    Austin.
 * [https://wordpress.org/plugins/qtranslate-x/](https://wordpress.org/plugins/qtranslate-x/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [John Clause](https://wordpress.org/support/users/johnclause/)
 * (@johnclause)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5712843)
 * Hi [@austeroid](https://wordpress.org/support/users/austeroid/): in theory, your
   solution should work, but it is not how qTranslate is meant to be used. If it
   does not work, then it is most likely because your `get_language_code()` does
   not return what it is supposed to return, or the output is compared to a wrong
   thing, like `en` instead of `EN`.
 * Here is a solution “by design”:
 *     ```
       <section class="hero home">
       <h1><?php _e('<!--:en-->Only show if selected language is EN<!--:--><!--:de-->Only show if selected language is DE<!--:-->'); ?></h1>
       </section>
       ```
   
 *  Thread Starter [Austeroid](https://wordpress.org/support/users/austeroid/)
 * (@austeroid)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5712921)
 * Hi John,
 * Thank you for your reply, i tried get_language_code() and WordPress doesn’t recognise
   it as a legit function.
 * So how would you separate the two homepages in 2 different languages? At the 
   moment, on my homepage, there are hardcoded elements that are shared between 
   the two. For example I will have 2 gallery sliders. Each one will contain each
   of their own slides in 2 languages.
 * The code to output the slide show is
 *     ```
       <section>
          <?php echo do_shortcode( '[new_royalslider id="1"]' ) ?> <!-- Slide show in english -->
           <?php echo do_shortcode( '[new_royalslider id="2"]' ) ?> <!-- Slide show in german -->
       </section>
       ```
   
 * I tried
 *     ```
       <?php
                           <!--:en-->
                           echo do_shortcode( '[new_royalslider id="1"]' )
                           <!--:-->
                           <!--:vi-->
                           echo do_shortcode( '[new_royalslider id="2"]' )
                           <!--:-->
                       ?>
       ```
   
 * but doesn’t work.
 * What are your thoughts on this? technically is there a way to have two different
   templates for 2 different languages?
 * Regards,
    Austin.
 *  Plugin Author [John Clause](https://wordpress.org/support/users/johnclause/)
 * (@johnclause)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5712923)
 * Normally, you would not need two templates. A template read the data from a page/
   post and you customize the data per language in a normal way using shortcodes
   with different arguments and different text. This normally is not done in the
   code, but rather in the editor of pages, which use the template.
    Does it make
   sense for your case?
 *  [Optimizr](https://wordpress.org/support/users/william-greatman/)
 * (@william-greatman)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5713009)
 * I do not think this would solve [@austeroid](https://wordpress.org/support/users/austeroid/)’
   s problem because I’m facing same problem here. I want to embed extra font css
   for my Burmese (Myanmar) page. My English page use some beautiful English web
   font so I can’t set all <body> tag to Myanmar font.
 * Since Myanmar font is not compatible with all computer yet, I have to embed Myanmar
   font for Burmese pages.
 * How can I embed css for specific language? How can I translate widget for different
   languages?
 *  [meiocheio](https://wordpress.org/support/users/meiocheio/)
 * (@meiocheio)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5713049)
 * You saved my life [@darkseal](https://wordpress.org/support/users/darkseal/).
 * Your code worked perfectly =)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get Current Language Code Function/Method’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/qtranslate-x_f9f9f9.svg)
 * [qTranslate X](https://wordpress.org/plugins/qtranslate-x/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/qtranslate-x/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/qtranslate-x/)
 * [Active Topics](https://wordpress.org/support/plugin/qtranslate-x/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/qtranslate-x/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/qtranslate-x/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [get](https://wordpress.org/support/topic-tag/get/)
 * [language](https://wordpress.org/support/topic-tag/language/)
 * [method](https://wordpress.org/support/topic-tag/method/)

 * 5 replies
 * 4 participants
 * Last reply from: [meiocheio](https://wordpress.org/support/users/meiocheio/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/get-current-language-code-functionmethod/#post-5713049)
 * Status: resolved