添加多个类,尤其是当它们必须基于某些条件显示时,可能会导致HTML输出不一致。为了正确设置格式并能够删除重复项或现有类,我们可以将它们转换为数组,并最终连接回字符串:
add_filter(\'admin_body_class\', static function ($classes) {
$classes = explode(\' \', $classes);
$classes = array_merge($classes, [
\'my-class-one\',
\'my-class-two\',
\'my-class-three\',
some_function(),
another_function(),
]);
return implode(\' \', array_unique($classes));
});