• 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

    • Microsoft is busy. Lots of changes to be released imminently for Windows server or soon. Also, lots happening for next version as well. Third party virus scanning software is being moved out of Kernel mode to avoid repeat of Crowdstrike incident. Windows Protected Mode and Windows Ready Print no longer require third party print drivers to be installed. New storage stack being developed. New NVME drivers now available for Windows Server 2025 to improve local NVME drive performance by 60+ percent. NVME-Of of fabric being worked on for next release to improve network access to NVME drives. ReFs (next file system) now has ability to boot and will become default file system in next release of Windows Server. ReFs improves on NTFS in several areas including resiliency and reliability and scalability. New update stack is being worked on to unify Windows updates, and updates for drivers and first party/3rd party application software. A stricter and more robust third-party driver certification program (ODI) is being worked on to improve performance, thermals, battery life, and reliability on modern Windows hardware by tightening how OEMs and IHVs (Intel, AMD, Qualcomm, NVIDIA, etc.) build and ship drivers. There is a tone more but too numerous to mention.
    • Now disable that stupid OneDrive backup request when Windows starts please. So unbelievably frustrating to only have “remind me later” instead of “no and never ask me again”
    • Hello, The Media Creation Tool is still at v10.0.26100.7019 from October 2025. Just looks like the backend has been updated. Regards, Aryeh Goretsky
    • Since they open sourced the calculator in Win 10/11 it is much better and can do a lot, I love it.
    • That's just silly imo. The lengths that man goes to just to avoid W11 is just nuts. Very, very few home users would do that. I will say this though, he is committed. Btw, I note on askwoody that Woody Leonhard passed away March, 2025 aged 73. His site was one of my favorites back in the day. Belated yes but RIP Woody.
  • Recent Achievements

    • One Month Later
      Markus94287 earned a badge
      One Month Later
    • Week One Done
      Markus94287 earned a badge
      Week One Done
    • One Year In
      Markus94287 earned a badge
      One Year In
    • Dedicated
      truespursfan earned a badge
      Dedicated
    • Rookie
      restore went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      +Edouard
      169
    3. 3
      PsYcHoKiLLa
      154
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!