Title: Language switcher shortcode or PHP?
Last modified: October 5, 2016

---

# Language switcher shortcode or PHP?

 *  Resolved [Dave](https://wordpress.org/support/users/deeve007/)
 * (@deeve007)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/)
 * Apologies if it’s published somewhere, but haven’t been able to find it: Is there
   a shortcode or PHP for displaying the language switcher anywhere in a template?
 * Thanks.

Viewing 15 replies - 1 through 15 (of 23 total)

1 [2](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/page/2/?output_format=md)

 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8253586)
 * You can use PHP code.
    Please read [https://wordpress.org/support/topic/how-to-make-only-one-flag/?replies=7](https://wordpress.org/support/topic/how-to-make-only-one-flag/?replies=7)
 *  Thread Starter [Dave](https://wordpress.org/support/users/deeve007/)
 * (@deeve007)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8253605)
 * Thank you. Apologies, I did look here and google for a while too.
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8344389)
 * Hi Everyone,
    I use wp-globus for the translation.
 * It gives me the option to write all the static pages in 2 different languages.
   But my main page is highly customized from the php source code and there is no
   option to translate the main page in wp-globus and this is normal because the
   main page content is directly edited in the index.php.
 * I would like to create a condition on the file index.php and also the header.
   php file that will detect the language from the wp-globus trigger variable or
   directly from the URL(because when wp-globus switchs to another language, i writes
   an url like [http://www.site.com/wordpressdirectoryname/AR](http://www.site.com/wordpressdirectoryname/AR)
   where AR is the language code.
 * So what i need is something like
 * <php [php detects language] ?> <php [if $language==AR] ?>
    Display text and images
   in AR language using html.
 * <php [else] ?>
    Display english content in HTML
 * <php [endif] ?>
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8344411)
 * You can use this piece of code
    (we are using lowercase for language codes )
 *     ```
       if ( WPGlobus::Config()->language == 'ar' ) {
         // code
       } else if ( WPGlobus::Config()->language == WPGlobus::Config()->default_language ) {
         // code
       }
       ```
   
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8344418)
 * You can see more code
    [https://wordpress.org/support/topic/how-to-make-only-one-flag/?replies=7](https://wordpress.org/support/topic/how-to-make-only-one-flag/?replies=7)
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8345431)
 * Hey Gor thanks for the fast reply but it doesn’t work, instead it displays both
   versions and the php code even when I put them in <php ?>. Do i need do do something
   before it?
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8345469)
 * Please, read
    [http://www.wpglobus.com/documentation/wpglobus-compatibility-with-themes-and-plugins/](http://www.wpglobus.com/documentation/wpglobus-compatibility-with-themes-and-plugins/)
   and you can check files wpglobus\includes\class-wpglobus-core.php wpglobus\includes\
   class-wpglobus-utils.php to get functions for translation and localize
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8347665)
 * Dear Gor, again thanks for the fast reply. I readed but i couldn’t find something
   helpful probably because i am a php beginner but for your reference i use cloudpress
   theme. I hopeyou can give me a beginner friendly solution. Thanks in advance,
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8347706)
 *     ```
       global $post;
       $post_content = $post->post_content;
       if ( WPGlobus::Config()->language == 'ar' ) {
         // Display text and images in ar language using html.
         echo apply_filters( 'the_content', $post_content );
       } else if ( WPGlobus::Config()->language == 'en' ) {
         // Display text and images in en language using html.
         echo apply_filters( 'the_content', $post_content );
       }
       ```
   
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348120)
 * Thanks again for your reply, i tried this code too but it is still displaying
   both versions and the php code, here is my source code:
 *     ```
       <?php
       /**
        * The main template file.
        *
        * This is the most generic template file in a WordPress theme
        * and one of the two required files for a theme (the other being style.css).
        * It is used to display a page when nothing more specific matches a query.
        * E.g., it puts together the home page when no home.php file exists.
        * Learn more: http://codex.wordpress.org/Template_Hierarchy
        *
        * @package cloudpress
        */
   
       get_header(); ?>
       <html><link rel="stylesheet" href="css/animate.css">
       </html>
       <?php if(is_home() || is_front_page()):?>
       <?php
           $slider = get_theme_mod('slider_disable',1);
           if($slider==1){
   
        ?>
   
       <section class="headerimg">
   
       <html>
   
       <div class="slidetext">
       <div class="slide-down">
       </div>
       </div>
       </html>
       </section>
       <?php }?>
       <?php else: ?>
       <section class="page-header">
       </section> <!-- /.end of section --> 
       <?php endif; ?>
       <div class="clearfix"></div>
       <section class="page-content">
   
         <div class="container">       
           <div class="row">
             <?php
                 $class = 'col-md-12';
                 $sidebar =  get_theme_mod('sidebar_position');
                   if ( !empty( $sidebar ) ) {
                       $sidebar_value = $sidebar;
                   }else {
                       $sidebar_value = 'right';
                   }
                 if ( $sidebar_value != 'none' ){
                   $class = 'col-md-9';
                 }
             ?>          
   
             <?php
                 if ($sidebar_value == 'left'){
   
                     get_sidebar('main');
                    }
             ?> </div>    
             <html>
              <style>
       body{
       color:black;
       }
       </style>
   
       <body>
       <div class="marqueecontainer"><marquee>Announcement</marquee></div>
       <br>
       <br>
       <h1>
   
       <php global $post;
       $post_content = $post->post_content;
       if ( WPGlobus::Config()->language == 'tw' ) {
         Chinese(TW) text and images
         echo apply_filters( 'the_content', $post_content );
       } else if ( WPGlobus::Config()->language == 'en' ) {
       ENGLISH TEXT AND images
         echo apply_filters( 'the_content', $post_content );
       }?>
   
       <?php
       $args = array( 'numberposts' => 1 );
       $lastposts = get_posts( $args );
       foreach($lastposts as $post) : setup_postdata($post); ?>
       	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
       	<?php the_content(); ?>
       <?php endforeach; ?>
       </div>
       </center>
   
       </body>
             </html>
   
         </div> <!-- /.end of container -->  
       </section>   <!-- /.end of section -->   
   
       <?php get_footer();?>
       ```
   
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348258)
 * Try change this
 *     ```
       foreach($lastposts as $post) : setup_postdata($post); ?>
       	<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
       	<?php the_content(); ?>
       <?php endforeach; ?>
       ```
   
 * to
 *     ```
       foreach($lastposts as $post) : setup_postdata($post); 
              $permalink = get_the_permalink();
              $permalink = WPGlobus_Utils::localize_url( $permalink, WPGlobus::Config()->language );
              $title = get_the_title();
              $content = get_the_content();
              ?>
       	<h2><a href="<?php echo $permalink; ?>"><?php echo apply_filters('the_title', $title ); ?></a></h2>
       	<?php echo apply_filters( 'the_content', $content ); ?>
       <?php endforeach; ?>
       ```
   
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348312)
 * Hey Dear Gor,
    Still no effect and displaying the php code:
 *     ```
       <?php
       /**
        * The main template file.
        *
        * This is the most generic template file in a WordPress theme
        * and one of the two required files for a theme (the other being style.css).
        * It is used to display a page when nothing more specific matches a query.
        * E.g., it puts together the home page when no home.php file exists.
        * Learn more: http://codex.wordpress.org/Template_Hierarchy
        *
        * @package cloudpress
        */
   
       get_header(); ?>
       <html><link rel="stylesheet" href="css/animate.css">
       </html>
       <?php if(is_home() || is_front_page()):?>
       <?php
           $slider = get_theme_mod('slider_disable',1);
           if($slider==1){
   
        ?>
   
       <section class="headerimg">
   
       <html>
   
       <div class="slidetext">
       <div class="slide-down">
       </div>
       </div>
       </html>
       </section>
       <?php }?>
       <?php else: ?>
       <section class="page-header">
       </section> <!-- /.end of section --> 
       <?php endif; ?>
       <div class="clearfix"></div>
       <section class="page-content">
   
         <div class="container">       
           <div class="row">
             <?php
                 $class = 'col-md-12';
                 $sidebar =  get_theme_mod('sidebar_position');
                   if ( !empty( $sidebar ) ) {
                       $sidebar_value = $sidebar;
                   }else {
                       $sidebar_value = 'right';
                   }
                 if ( $sidebar_value != 'none' ){
                   $class = 'col-md-9';
                 }
             ?>          
   
             <?php
                 if ($sidebar_value == 'left'){
   
                     get_sidebar('main');
                    }
             ?> </div>    
             <html>
              <style>
       body{
       color:black;
       }
       </style>
   
       <body>
       <div class="marqueecontainer"><marquee>Announcement</marquee></div>
       <br>
       <br>
       <h1>
   
       <php global $post;
       $post_content = $post->post_content;
       if ( WPGlobus::Config()->language == 'tw' ) {
         Chinese(TW) text and images
         echo apply_filters( 'the_content', $post_content );
       } else if ( WPGlobus::Config()->language == 'en' ) {
       ENGLISH TEXT AND images
         echo apply_filters( 'the_content', $post_content );
       }?>
   
   
       <?php
       $args = array( 'numberposts' => 1 );
       $lastposts = get_posts( $args );
       foreach($lastposts as $post) : setup_postdata($post); 
              $permalink = get_the_permalink();
              $permalink = WPGlobus_Utils::localize_url( $permalink, WPGlobus::Config()->language );
              $title = get_the_title();
              $content = get_the_content();
              ?>
       	<h2><a href="<?php echo $permalink; ?>"><?php echo apply_filters('the_title', $title ); ?></a></h2>
       	<?php echo apply_filters( 'the_content', $content ); ?>
       <?php endforeach; ?>
       </div>
       </center>
   
       </body>
             </html>
   
         </div> <!-- /.end of container -->  
       </section>   <!-- /.end of section -->   
   
       <?php get_footer();?>
       ```
   
 *  Plugin Support [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * (@alexgff)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348336)
 * You forget remove unneeded code
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348382)
 * Dear Gor,
    I removed ` <section class=”headerimg”>
 * <html>
 * <div class=”slidetext”>
    <div class=”slide-down”> </div> </div> </html> </section
   > `and` <section class=”page-header”> </section> <!– /.end of section –> ` , 
   still not working
    -  This reply was modified 9 years, 7 months ago by [Luciano 1](https://wordpress.org/support/users/kissmoney/).
 *  [Luciano 1](https://wordpress.org/support/users/kissmoney/)
 * (@kissmoney)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/#post-8348583)
 * Also, i just removed <h1> and written the code like this: `
    <?php global $post;?
   > <?php $post_content = $post->post_content; ?> <?php if ( WPGlobus::Config()-
   >language == ‘tw’ ) {?> <html>Chinese(TW) text and images</html> <?php echo apply_filters(‘
   the_content’, $post_content ); } ?> <php else if ( WPGlobus::Config()->language
   == ‘en’ ) {?> <html> <center><h2><b>Title</b></h2> <div class=”mainpagetext”>
   ENGLISH TEXT AND images </div> </html> <php echo apply_filters( ‘the_content’,
   $post_content ); }?> ` Now the Chinese version is hidden until i press the chinese
   button but the english vesion is always there and most of the php code disappeared
   except: language == ‘en’ ) {?>

Viewing 15 replies - 1 through 15 (of 23 total)

1 [2](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/page/2/?output_format=md)

The topic ‘Language switcher shortcode or PHP?’ is closed to new replies.

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

 * 23 replies
 * 3 participants
 * Last reply from: [Alex Gor](https://wordpress.org/support/users/alexgff/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/language-switcher-shortcode-or-php/page/2/#post-8365485)
 * Status: resolved