Last active
January 21, 2019 02:45
-
-
Save franckweb/9ce9e0cd1a9abfe3f27137b0413524ca to your computer and use it in GitHub Desktop.
Polylang
This file contains hidden or 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 | |
/* language switcher */ | |
$translations = pll_the_languages( array( | |
'show_flags' => 0, | |
'hide_if_no_translation' => 1, | |
'hide_current'=> 1, | |
'raw' => 1) | |
); | |
if (count($translations) > 0){ | |
$lang_switcher_text = ''; | |
foreach ($translations as $translation){ | |
$lang_switcher_text .= | |
'<li><a href="' . $translation['url'] . '">' . | |
'<img src="' . $translation['flag'] . '" /> ' . $translation['name'] . | |
'</a></li>'; | |
} | |
$lang_switcher = | |
'<div id="language-switcher-header" class="row"> ' . | |
'<ul>' . $lang_switcher_text . '</ul>' . | |
'</div>'; | |
} | |
echo $lang_switcher; | |
?> | |
<?php | |
/* get corresponded translated post id (works with post_types too) */ | |
global $post; | |
$polylangPostID = pll_get_post($post->ID); | |
$translatedPost = get_post($polylangPostID); | |
$title = apply_filters( 'the_title', $translatedPost->post_title ); | |
$content = apply_filters( 'the_content', $translatedPost->post_content ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment