Title: Conditional language switcher display
Last modified: August 20, 2016

---

# Conditional language switcher display

 *  Resolved [zeshark](https://wordpress.org/support/users/zeshark/)
 * (@zeshark)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/)
 * I am trying to get the language switcher to be displayed in my template only 
   if a translation exist. The default behaviour where the home page
 * Reading through the support articles, I found references and sample code about
   the pll_the_language_link filter, but being the php dummy that I am, I struggle
   to find or write a function that I can apply a test on from my template to know
   whether a translation exists, and call pll_the_languages() depending on the result.
   Did not find any in api.php at least.
 * Any simple solution ?
 * Help much appreciated !
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

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

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309448)
 * No need for a lot of PHP code as Polylang already includes this. You can use 
   for example:
 *     ```
       <ul><?php pll_the_languages(array('hide_if_no_translation' => 1)); ?></ul>
       ```
   
 *  Thread Starter [zeshark](https://wordpress.org/support/users/zeshark/)
 * (@zeshark)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309533)
 * Thanks a lot for the reply.
    Does not do exactly what I need as I would like 
   to display a div only if a translation of a post exists.
 *     ```
       <?php if [condition]: ?>
       <div id="LanguageSwitcher" class="styleLanguageSwitcher" >
       <ul><?php pll_the_languages(array('show_flags'=>1,'show_names'=>1,'force_home'=>0, 'hide_if_no_translation'=>1, 'hide_current'=>1));?></ul>
       </div>
       <?php endif; ?>
       ```
   
 *  [maxoud](https://wordpress.org/support/users/maxoud/)
 * (@maxoud)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309590)
 *     ```
       <?php
       $switcher = pll_the_languages(array('show_flags'=>1,'show_names'=>1,'force_home'=>0, 'hide_if_no_translation'=>1, 'hide_current'=>1));
       if($switcher): ?>
       <div id="LanguageSwitcher" class="styleLanguageSwitcher" >
       <ul><?php echo $switcher ?></ul>
       </div>
       <?php endif; ?>
       ```
   
 *  Thread Starter [zeshark](https://wordpress.org/support/users/zeshark/)
 * (@zeshark)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309592)
 * Thanks a lot for your suggestion !
    Unfortunately, it does not work. The language
   switcher gets displayed at the first function call.
 *     ```
       $switcher = pll_the_languages(array('show_flags'=>1,'show_names'=>1,'force_home'=>0, 'hide_if_no_translation'=>1, 'hide_current'=>1));
       ```
   
 * Also, $switcher seems to be false in all cases.
 *  [maxoud](https://wordpress.org/support/users/maxoud/)
 * (@maxoud)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309593)
 * Oh, sorry, it’s my fault. You need to add `echo` argument:
 *     ```
       <?php
       $switcher = pll_the_languages( array(
       	'show_flags'=>1,
       	'show_names'=>1,
       	'force_home'=>0,
       	'hide_if_no_translation'=>1,
       	'hide_current'=>1,
       	'echo' => 0
       ) );
       ```
   
 *  Thread Starter [zeshark](https://wordpress.org/support/users/zeshark/)
 * (@zeshark)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309594)
 * It WORKS !
    Thanks a million, I really appreciate the help.
 * For the convenience of others, the final code: this displays in the div only 
   the available language(s), and no div if there is no translation available.
 *     ```
       <?php
       $switcher = pll_the_languages( array(
       	'show_flags'=>1,
       	'show_names'=>1,
       	'force_home'=>0,
       	'hide_if_no_translation'=>1,
       	'hide_current'=>1,
       	'echo' => 0
       ) );
       if($switcher): ?>
       <div id="LanguageSwitcher" class="styleLanguageSwitcher" >
       <ul><?php echo $switcher ?></ul>
       </div>
       <?php endif; ?>
       ```
   

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

The topic ‘Conditional language switcher display’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [zeshark](https://wordpress.org/support/users/zeshark/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-language-switcher-display/#post-3309594)
 * Status: resolved