Created
September 17, 2018 12:44
-
-
Save nicomollet/a7283d8c3a2707f7be04f3f507437e71 to your computer and use it in GitHub Desktop.
Elementor get polylang translation of template
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 | |
/** | |
* Elementor get polylang translation of template | |
*/ | |
add_filter( 'elementor/theme/get_location_templates/template_id', function( $post_id ) { | |
if(!is_admin()){ | |
if ( function_exists( 'pll_get_post' ) ) { | |
$translation_post_id = pll_get_post( $post_id ); | |
if ( null === $translation_post_id ) { | |
// the current language is not defined yet | |
return $post_id; | |
} elseif ( false === $translation_post_id ) { | |
//no translation yet | |
return $post_id; | |
} elseif ( $translation_post_id > 0 ) { | |
// return translated post id | |
return $translation_post_id; | |
} | |
} | |
} | |
return $post_id; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment