可以在设置值之前使用过滤器修改该值
function __language_attributes($lang){
// ignore the supplied argument
$langs = array( \'en-US\', \'KO\', \'JA\' );
// change to whatever you want
$my_language = $langs[0];
// return the new attribute
return \'lang="\'.$my_language.\'"\';
}
add_filter(\'language_attributes\', \'__language_attributes\');
然后只需确保您的主题标头具有正确的php函数
<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
<head>
- https://codex.wordpress.org/Function_Reference/language_attributes另一种方法是在调用过滤器之前在全局变量中设置语言。
// Make this variable global
global $__language_attribute;
// Set the language we want to use
$__language_attribute = \'en-US\';
// Listen for the language filter
add_filter(\'language_attributes\', \'__language_attributes_use_global\');
function __language_attributes_use_global($lang){
global $__language_attribute;
return "lang=\\"$__language_attribute\\"";
}
ALTERNATE
// set your language here
$my_lang = \'KO\';
// subscribe with closure to apply this value later
add_filter(\'language_attributes\', function($lang) use ($my_lang) {
return \'lang="\' . $my_lang . \'"\';
});