Created
October 11, 2017 08:15
-
-
Save cyberwani/6e22d55707c2328e08568dfff1bfe36c to your computer and use it in GitHub Desktop.
Shortcode to display content based on current language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( ! function_exists('polylang_content_func') ){ | |
function polylang_content_func( $atts, $content = "" ) { | |
$atts = shortcode_atts( array( | |
'lang' => '', | |
), $atts ); | |
extract($atts); | |
// Bail early if no language provided | |
if( $lang == '' ) return; | |
$pll_current_language = pll_current_language(); | |
// Bail early if current language is not same as provided language | |
if( $pll_current_language != $lang ) return; | |
return do_shortcode($content); | |
} | |
} | |
add_shortcode( 'polylang_content', 'polylang_content_func' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Conditional Shortcode Based on Language ( for another chance to find it ...)
Wow! Thank you very much, this code runs just perfect!
(for those who are not that familiar with coding, like me :-) ):
Insert the above code into your functions.php of your child-theme.
Use the short code in your wordpress pages/widget etc. like this:
[polylang_content lang=en] Language is displayed in english [/polylang_content]
[polylang_content lang=de] Sprache wird in deutsch angezeigt [/polylang_content]
Great! Many thanks again!