• 0

Polylang WP plugin: create a language-selector with according flags


Question

hello dear community, 

 

I have installed Polylang WP plugin for one site see the conceptual view: 



                                                   language-switcher: de :: fr :: it ::es :: pt :: eng :: ...--+
                                                   |                                                           |
                                                   +-----------------------------------------------------------+
+--------------------------------------------------------------------------------------------------------------+
|                                                                                                              |
|   +-------------------+ +------------------+ +----------------------------------+ +-------------------+      |
|   |                   | |                  | |                ||                | |                   |      |
|   |        Item 1     | |        Item 2    | |      Item 3    ||     Item 4     | |        Item 5     |      |
|   |                   | |                  | |                ||                | |                   |      |
|   |                   | |                  | |                ||                | |                   |      |
|   |                   | |                  | |                ||                | |                   |      |
|   +-------------------+ +------------------+ +----------------------------------+ +-------------------+      |
|                                                                                                              |
+--------------------------------------------------------------------------------------------------------------+
[/Code]


See i have the following languages: [Code] de :: fr :: it ::es :: pt :: eng  [/Code]

so we accordingly need to add flags but its look like funny. Therefore i came up with a sidebar in my theme (twentyseventeen the theme with the parallax-effect), 
and add it to header the following code:

[Code]
<div class="drop-dl">
  <a class="lang-chose" href="#"><img src=""> please now chose the language for the site - we have several ones - just choose now! </a>
  <?php get_sidebar(); ?>
</div>[/Code]

susequently: in the admin page of my site i need to configure at the so called widget-section the display of the language-selector. This is needed to get a good
overview for the user of the site: Therefore i have to set up the Language-Selector to the Sidebar: that task brings up a unsorted Lists from languages.
what comes next: in the next step i add small script and css code to get this work, here is CodePen demo link

furthermore: With this (following) php code, i am trying to have more control over positioning the widget in template.


[Code]if(function_exists('pll_the_languages')){
    pll_the_languages( array( 'show_flags' => 1,'show_names' => 0  ));
}[/Code]


This subsequently should help us to show up the following languages/respectively flags of nations :[Code] de :: fr :: it ::es :: pt :: eng  [/Code]

[Code]<!-- outputs a list of languages names -->
<ul>
<?php pll_the_languages(); ?>
</ul> 
<!-- outputs a flags list (without the according languages names - that is: the names of the nations) -->
<ul>
<?php pll_the_languages( array( 'show_flags' => 1,'show_names' => 0 ) ); ?>
</ul>
<!-- outputs a dropdown list of languages names -->
<?php pll_the_languages( array( 'dropdown' => 1 ) ); ?>[/Code]


[b]question:[/b] how to do this... 


can i display the language and the flag - both!?


[Code]
$translations = pll_the_languages( array( 'raw' => 1 ) );
[/Code]


The above mentioned function will return an array of arrays, one array per language with the following entries in the array:

[id] => language id
[slug] => language code used in urls
[name] => language name
[url] => url of the translation
[flag] => url of the flag
[current_lang] => true if this is the current language, false otherwise


again: any suggestion is welcome :) Because this solution should go to  work with "Polylang widget"

2 answers to this question

Recommended Posts

  • 0

hello dear+ Human.Online. 

 

first of all - many many thanks for the quick reply.  Yes a bit simillar  - but the ohter thread does no contain su much code - and ideas. 

At the moment i am trying to get these poly-lang-things done. 

 

a big big SORRY if there some threads might  seem to be pretty close to each other.  

I encountered - the more i write the more i learn bout the Wordpress-issues. This helps me alot - therefore some days i might have pretty same issues i work on... 

sorry for that.

 

Above all :  i am so glad to be here at this great place - it is such a good thing being here at the forums.. 

 

 

have a great day. 

 

 

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • XnView 2.52.2 by Razvan Serea XnView is freeware software that allows you to view and convert graphic files. It's very fast and easy to use. But more importantly it supports more than 500 graphics formats! Import about 500 graphic file formats Export about 50 graphic file formats Multipage TIFF, Animated GIF, Animated ICO support Image IPTC, EXIF metadata support EXIF auto rotation support IPTC editing Resize, rotate, crop support Lossless rotate & crop (jpeg) support Adjust brightness, contrast... Auto levels, contrast Modify number of colors Apply filters (blur, average, emboss, ...) Apply effects (lens, wave, ...) Fullscreen mode Slide show with effects Batch convert, batch rename Create WEB page easily Screen capture Create contact Sheet Create or edit Multi-page file (TIFF, DCX, LDF) TWAIN & WIA support (Windows only) Print support (Windows only) Drag & Drop support (Windows only) Compare image side by side Filmstrip layout 44 languages support (Windows only) XnView 2.52.2 changelog: NConvert: -xyb for JPEGli XnView vs XnView MP: XnView is the classic, lightweight version with basic features and Windows-only support. XnView MP is the modern, cross-platform version with an improved interface, better performance, and extended format support. Download: XnView 2.52.2 Installer | Standalone | ~24.0 MB (Non-commercial freeware) Download: XnView MP 1.9.2 64-bit | Standalone | ~100.0 MB Download: XnView MP 1.9.2 32-bit | Standalone | ~60.0 MB View: XnView Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Correct. You don’t buy anything that’s free (if it were).
    • Vivaldi 7.4.3684.52 by Razvan Serea Vivaldi is a cross-platform web browser built for – and with – the web. A browser based on the Blink engine (same in Chrome and Chromium) that is fast, but also a browser that is rich in functionality, highly flexible and puts the user first. A browser that is made for you. Vivaldi is produced with love by a founding team of browser pioneers, including former CEO Jon Stephenson von Tetzchner, who co-founded and led Opera Software. Vivaldi’s interface is very customizable. Vivaldi combines simplicity and fashion to create a basic, highly customizable interface that provides everything a internet user could need. The browser allows users to customize the appearance of UI elements such as background color, overall theme, address bar and tab positioning, and start pages. Vivaldi features the ability to "stack" and "tile" tabs, annotate web pages, add notes to bookmarks and much more. Vivaldi 7.4.3684.52 changelog: [Address bar] URL is searched instead of opening (VB-117198) [Chromium] Update to 136.0.7103.179 [Settings][Workspaces] Add Workspace Rule button hidden by 4th rule (VB-117181) Download: Vivaldi 64-bit | 125.0 MB (Freeware) Download: Vivaldi 32-bit | ARM64 View: Vivaldi Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • NTLite 2025.06.10482 by Razvan Serea NTLite is a Windows configuration tool that allows you to modify your existing Windows install or an image yet to be deployed, remove Windows components, configure and integrate, speed up the Windows deployment process. Reduce Windows footprint on your RAM and storage drive memory. Remove components of your choice, guarded by compatibility safety mechanisms, which speed up finding that sweet spot. Windows Unattended feature support, providing many commonly used options on a single page for easy setup. Easily integrate a single or multiple drivers, update or language packages. Package integration features smart sorting, enabling you to seamlessly add packages for integration and the tool will apply them in the appropriate order, keeping hotfix compatibility in check. One of the important new features of NTLite (compared to its predecessors) is the ability to modify an already installed the operating system, by removing unnecessary components. Supports Windows 11, 10, 8.1 and 7, x86 and x64, live and image. Server editions of the same versions, excluding support for component removals and feature configuration. ARM64 image support in the alpha stage. Does not support Checked/Debug, Embedded, IoT editions, nor Vista or XP. NTLite 2025.06.10482 changelog: Fix Image: Image optimization would be skipped if both boot.wim and install.wim would keep only one edition Image: Crash after exporting unloaded image in certain situations Upgrade UI-Translation: Thanks for Turkish (Salih DURDU), Georgian (Anonymous) Download: NTLite 64-bit | 21.5 MB (Free, paid upgrade available) Download: NTLite 32-bit | 19.3 MB Link: NTLite Home Page | NTLite Features | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
    • One Month Later
      Karan Khanna earned a badge
      One Month Later
    • Week One Done
      Karan Khanna earned a badge
      Week One Done
    • First Post
      MikeK13 earned a badge
      First Post
    • Week One Done
      OHI Accounting earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      681
    2. 2
      ATLien_0
      265
    3. 3
      Michael Scrip
      202
    4. 4
      +FloatingFatMan
      166
    5. 5
      Steven P.
      141
  • Tell a friend

    Love Neowin? Tell a friend!