R R D E V S

Loading

By rrdevs March 3, 2023 Plugin Tips WordPress Tips

Polylang language switcher for WordPress Plugin

Default Language Php Code:
<?php pll_the_languages( array( 'dropdown' => 1, 'hide_current=> 1 ) ); ?>
More php code try it:
<?php 
// add "raw" key and save data to variable

$langs_array = pll_the_languages( array( 'dropdown' => 1, 'hide_current' => 1, 'raw' => 1 ) );

?>


<?php if ($langs_array) : ?>
  <div class="drop-block lang">
    <?php foreach ($langs_array as $lang) : ?>
      <a href="<?php echo $lang['url']; ?>" class="drop-block__link">
        <?php echo $lang['slug']; ?>
        </a>
    <?php endforeach; ?>
  </div>
<?php endif; ?>
 

Polylang Language Switcher Code: A Powerful Tool for Multilingual Websites

If you're building a multilingual website, you're likely familiar with the Polylang plugin for WordPress. Polylang is a popular tool for managing content in multiple languages, allowing you to easily translate pages, posts, and other site elements. But did you know that Polylang also includes a powerful language switcher code that can greatly enhance the user experience of your site? In this article, we'll explore the Polylang language switcher code and how it can benefit your website.

What is the Polylang Language Switcher Code?

The Polylang language switcher code is a piece of code that allows you to display a language switcher on your website. The switcher allows users to easily switch between different languages on your site, making it easier for them to navigate and access content. The code is included in the Polylang plugin and can be added to your site using a widget, shortcode, or PHP code.

Benefits of Using the Polylang Language Switcher Code

  1. Improved User Experience
By including a language switcher on your site, you're making it easier for users to access content in their preferred language. This can greatly improve the user experience of your site, making it more user-friendly and accessible.
  1. Increased Engagement
When users can easily access content in their preferred language, they're more likely to engage with your site and spend more time exploring your content. This can lead to increased engagement and ultimately, increased conversions and revenue.
  1. Better SEO
Having a multilingual website can also improve your SEO efforts. By providing content in multiple languages, you're opening up your site to a wider audience and potentially increasing your reach. Additionally, having a language switcher on your site can make it easier for search engines to crawl and index your content in multiple languages.

How to Implement the Polylang Language Switcher Code

Polylang language switcher for Wordpress Plugin   Implementing the Polylang language switcher code is relatively simple. First, make sure you have the Polylang plugin installed and activated on your site. Then, you can add the language switcher using a widget, shortcode, or PHP code.   If you're using a widget, simply go to Appearance > Widgets and drag the Polylang Language Switcher widget to your desired location. You can customize the widget settings to choose which languages to display and how to display them.   If you're using a shortcode, simply add the following code to your post or page where you want the language switcher to appear:  
[polylang-switcher]

If you're using PHP code, you can add the following code to your site's header.php file:

<?php if(function_exists('pll_the_languages')) { $languages = pll_the_languages(array('show_flags'=>1,'show_names'=>0)); if(!empty($languages)) { echo '<ul>'; foreach($languages as $language) { echo '<li>'; echo '<a href="'.$language['url'].'">'; echo '<img src="'.$language['flag'].'" alt="'.$language['slug'].'" />'; echo '</a>'; echo '</li>'; } echo '</ul>'; } } ?>  

Conclusion

The Polylang language switcher code is a powerful tool for multilingual websites. By providing an easy way for users to switch between languages, you can greatly improve the user experience of your site and potentially increase engagement and conversions. Implementing the code is relatively simple and can be done using a widget, shortcode, or PHP code. If you're building a multilingual website, be sure to take advantage of the Polylang language switcher code.

Leave a Reply

Your email address will not be published. Required fields are marked *