Skip to content

Instantly share code, notes, and snippets.

@beovulf
Created December 1, 2016 08:19
  • Star 10 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save beovulf/5a1c26bec2eadd7bde413fc81df31771 to your computer and use it in GitHub Desktop.
If else language wordpress (polylang)
<?php
$currentlang = get_bloginfo('language');
if($currentlang=="en-GB"):
?>
<?php elseif($currentlang=="pl-PL"): ?>
<?php endif; ?>
@CultureInspired
Copy link

you beautiful bastard <3

@ebkjiud
Copy link

ebkjiud commented Oct 25, 2017

$currentlang=="en-GB" or $currentlang == "en-GB"

@MikeiLL
Copy link

MikeiLL commented Apr 25, 2018

Nice! For me when I print_r the $currentlang it was All Caps, so just to be sure:

$currentlang = strtoupper(get_bloginfo('language'));

@giorgioriccardi
Copy link

giorgioriccardi commented May 15, 2018

starting from your snippet I solved my issue and following this other snippet from https://css-tricks.com/forums/topic/php-html-lang-attribute-if-statement/ I ended up also solving the problem for different versions of "en-GB"," en-US", "en-CA" etc, like this:

<?php if(ICL_LANGUAGE_CODE=='en'): ?>
// do stuff
<?php elseif(ICL_LANGUAGE_CODE=='fr'): ?>
// do other stuff
<?php endif; ?>

@Altug
Copy link

Altug commented Oct 18, 2019

<3 Thanks a lot!

@Zoylander
Copy link

giorgioriccardi, thank you!

@cquesadad
Copy link

Great solution! Still working :)

@jguiss
Copy link

jguiss commented Nov 26, 2023

Thank you very much, I was looking for this so much

@Altug
Copy link

Altug commented Nov 27, 2023

This helped me a lot! Thank you for sharing.

@borodin-dev
Copy link

starting from your snippet I solved my issue and following this other snippet from https://css-tricks.com/forums/topic/php-html-lang-attribute-if-statement/ I ended up also solving the problem for different versions of "en-GB"," en-US", "en-CA" etc, like this:

<?php if(ICL_LANGUAGE_CODE=='en'): ?> // do stuff <?php elseif(ICL_LANGUAGE_CODE=='fr'): ?> // do other stuff <?php endif; ?>

thanks 🤝
great solution. this helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment