Title: Using flags for language switch
Last modified: August 31, 2016

---

# Using flags for language switch

 *  Resolved [candy2012](https://wordpress.org/support/users/candy2012/)
 * (@candy2012)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/)
 * Hi again 🙂
 * Can you guide us about how to use flags instead of text for the language switch
   in our theme?!
 * In the code you gave, I’ve noticed the language texts are dynamically generated
   so I cannot figure out how to use 3 flags for my 3 languages instead!?!
 * Thanks in advance
 * [https://wordpress.org/plugins/sublanguage/](https://wordpress.org/plugins/sublanguage/)

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

 *  Plugin Author [maximeschoeni](https://wordpress.org/support/users/maximeschoeni/)
 * (@maximeschoeni)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/#post-7041995)
 * Of course, that’s easy 🙂 Just prepare 3 png pictures with filename corresponding
   to your language slugs (e.g: en.png, fr.png, de.png) and put theme in the images
   directory of your theme folder. Then you can add this code in your function.php:
 *     ```
       add_action('sublanguage_custom_switch', 'my_custom_switch', 10, 2); 
   
       function my_custom_switch($languages, $sublanguage) {
   
       ?>
       <ul>
       <?php foreach ($languages as $language) { ?>
           <li class="<?php echo $language->post_name; ?> <?php if ($sublanguage->current_language->ID == $language->ID) echo 'current'; ?>">
               <a href="<?php echo $sublanguage->get_translation_link($language); ?>">
       			<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/<?php echo $language->post_name; ?>.png" alt="" width="" height="" />
       		</a>
           </li>
       <?php } ?>
       </ul>
       <?php 
   
       }
       ```
   
 *  Thread Starter [candy2012](https://wordpress.org/support/users/candy2012/)
 * (@candy2012)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/#post-7042049)
 * Cool! Works like a charm 🙂
 * Thank you!!!
 *  [Laura](https://wordpress.org/support/users/syccylinders/)
 * (@syccylinders)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/#post-8185185)
 * Hi, It’s not working for me T^T, I have on the menu one language and inside of
   him another language:
 *     ```
       language
           language
       ```
   
 * And the html code is:
 *     ```
       <div class="menu">
           <ul id="menu" class="nav tc-hover-menu">
                <li class="sublanguage active_language ... menu-item-1025">
                    <a data-test="joie" href="website">ES <strong class="caret"></strong>
                    </a>
                    <ul class="dropdown-menu" style="left: -95.375px;">
                          <li class="sublanguage ... menu-item-1026">
                               <a href="website in english">EN</a>
                          </li>
                    </ul>
                </li>
           </ul>
       </div>
       ```
   
 * And my theme is Customizr, and the path of images is:/wp/wp-content/themes/customizr/
   inc/assets/img
    -  This reply was modified 9 years, 8 months ago by [Laura](https://wordpress.org/support/users/syccylinders/).
    -  This reply was modified 9 years, 8 months ago by [Laura](https://wordpress.org/support/users/syccylinders/).
    -  This reply was modified 9 years, 8 months ago by [Laura](https://wordpress.org/support/users/syccylinders/).
 *  [maxime](https://wordpress.org/support/users/max345/)
 * (@max345)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/#post-8185554)
 * Hello,
 * Sorry but the solution I gave only work when the language switch is custom or
   in a widget, but not inside menu. I’ll try to improve this in the future.

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

The topic ‘Using flags for language switch’ is closed to new replies.

 * ![](https://ps.w.org/sublanguage/assets/icon-128x128.png?rev=1197494)
 * [Sublanguage](https://wordpress.org/plugins/sublanguage/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sublanguage/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sublanguage/)
 * [Active Topics](https://wordpress.org/support/plugin/sublanguage/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sublanguage/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sublanguage/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [maxime](https://wordpress.org/support/users/max345/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/using-flags-for-language-switch/#post-8185554)
 * Status: resolved