Last active
February 13, 2019 16:45
-
-
Save emasantos/fcb8ae51b71d3d1b87664aced45d6960 to your computer and use it in GitHub Desktop.
Set default language with Wordpress Polylang plugin.
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 | |
add_filter('the_content', 'lngSetDefaultLanguageAsPortuguese'); | |
/** | |
* @param string $content | |
* @return string | |
*/ | |
function lngSetDefaultLanguageAsPortuguese($content) | |
{ | |
/** WP_Post $post */ | |
global $post; | |
if (!function_exists('pll_get_post_language')){ | |
return $content; | |
} | |
if (!function_exists('pll_set_post_language')){ | |
return $content; | |
} | |
/** @var string|bool $postLanguage */ | |
$postLanguage = pll_get_post_language($post->ID); | |
if ($postLanguage === FALSE){ | |
pll_set_post_language($post->ID, 'pt'); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment