Skip to content
  • SuomeksiSuomeksi
  • In EnglishIn English
  • Networking
    • WiFi/WLAN
    • MikroTik
    • Ubiquiti
  • Security
    • General
    • Wireless
  • Software
    • WordPress

Tag: Polylang

Polylang language menu

How to create the language menu in the upper right corner using WordPress and Polylang?

Polylang language menu

This is a bilingual site: Finnish and English. There are multiple language plugins for WordPress and this site uses Polylang. Polylang is very nice and useful, but lacks the menu type so common in Finland: Finnish | Swedish | English. Writing a standalone plugin for such a menu turned out to be complicated, so this article will guide you to create it by hand.

The language menu requires changes to the theme. The best starting point is to create a child theme and there are multiple guides available to do that. When you have a child theme, add this to the style.css file:

/* Languages horizontally */ 
#language ul { margin: 0; padding: 0; } 
li.lang-item { list-style-type: none; display: inline; } 
li.lang-item:before { content: " | "; } 
li.lang-item:first-child:before { content: none; }

The functions.php file in the theme needs a definition for a new widget area:

register_sidebar( array(
        'name'          => 'Language',
        'id'            => 'language',
        'description'   => 'Polylang switcher area.',
        'before_widget' => '<div id="language">',
        'after_widget'  => '</div>'
) );

You need to add the widget area defined above to the header.php in the spot of your choice:

<aside id="language-nav" role="navigation">
    <?php dynamic_sidebar( 'language' ); ?>
</aside><!-- .language-nav-widgets -->

Finally add Language Switcher widget to Language widget are in WordPress Dashboard.

You can align the widget area to the right by adding for example this code to the style.css:

aside#language-nav {
  text-align: right;
  margin-left: auto;
}
Author Petri RiihikallioPosted on 20.12.201604.06.2017Categories WordPressTags Polylang2 Comments on Polylang language menu

Metis Oy

  • Front Page
  • Fix your WiFi network!
  • Contact
  • Petri Riihikallio

Latest articles

  • Fix GCP UniFi Controller certificate issue
  • CWNE#307, Petri Riihikallio
  • Decibels
  • Wi-Fi Roaming
  • Automatic Wi-Fi channel management
  • WPA3 is the latest Wi-Fi Protected Access
  • Tuning your Wi-Fi by adjusting transfer rates
  • Increase your cell phone battery life with a small change in the Wi-Fi network
  • Wi-Fi Repeaters, WDS, Mesh and Other Wireless Backbones
  • How many users can one Wi-Fi access point support?
  • Networking
    • WiFi/WLAN
    • MikroTik
    • Ubiquiti
  • Security
    • General
    • Wireless
  • Software
    • WordPress
Metis.fi Proudly powered by WordPress