Forked from nicomollet/elementor-template-polylang-translation.php
Created
September 10, 2019 14:15
-
-
Save ulziibat-n/f6e8aec17e930409243a169899ba3fb5 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