php 从WordPress主题中删除Body类的作者名称

yyhrrdl8  于 5个月前  发布在  PHP
关注(0)|答案(1)|浏览(64)

有没有什么方法可以从body_class()中删除作者名?有没有什么特定的过滤器可以从body类中只删除作者名?
请帮帮我

tcbh2hod

tcbh2hod1#

你可以通过在functions.php文件中添加一个过滤器来从body_class()函数中删除类。在你的例子中是'author'类。

add_filter('body_class', function (array $classes) {
   if (in_array('author', $classes)) {
      unset( $classes[array_search('author', $classes)] );
   }
   return $classes;
});

字符串
您可以在https://developer.wordpress.org/reference/functions/get_body_class/中找到类名引用的完整列表,并从https://developer.wordpress.org/reference/functions/body_class/中查看更多细节。
您也可以查找特定的类名结果并替换它。您有两个:一个是author-name,一个是author-id。

add_filter( 'body_class', 'replace_author_bob_name' );
function replace_author_bob_name( $classes ) {
  // You have all the classes in $classes
  // Replaces author-bob with author-hello
  $new_classes = array();
  foreach($classes as $cls) {
  
    if ($cls == "author-bob") $new_classes[] = "author-hello";
    else $new_classes[] = $cls;
  }
  return $new_classes;
}

相关问题