PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How to get the active language in WordPress Polylang

 October 09, 2022     php, polylang, wordpress     No comments   

Issue

I have setup Polylang on my WP and created pages for those 2 different languages (EN, GR). But I want to override a plugin and present some strings in greek if the selected Frontpage language is in Greek. I have tested with get_locale() and and get_bloginfo('language'), but both of them return the locale of the Administrator side which is en_US.

I have also tried with $_SERVER['REQUEST_URI'] of PHP_INFO, because when in EN the address bar contain the /en/ part, but I don't get the correct addres, rather a json request address created for the current request.

How I can get the frontend user language?


Solution

I have finally succeeded to get the current language with

isset($_COOKIE['pll_language']) ? $_COOKIE['pll_language'] : false;

and it returns "en" or "el" depending the active language.



Answered By - ToroLoco
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing