Skip to content

Instantly share code, notes, and snippets.

@emasantos
Last active February 13, 2019 16:45
Show Gist options
  • Save emasantos/fcb8ae51b71d3d1b87664aced45d6960 to your computer and use it in GitHub Desktop.
Save emasantos/fcb8ae51b71d3d1b87664aced45d6960 to your computer and use it in GitHub Desktop.
Set default language with Wordpress Polylang plugin.
<?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