Skip to content

Instantly share code, notes, and snippets.

@franckweb
Last active January 21, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franckweb/9ce9e0cd1a9abfe3f27137b0413524ca to your computer and use it in GitHub Desktop.
Save franckweb/9ce9e0cd1a9abfe3f27137b0413524ca to your computer and use it in GitHub Desktop.
Polylang
<?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