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

yyhrrdl8  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(240)

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

tcbh2hod

tcbh2hod1#

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

  1. add_filter('body_class', function (array $classes) {
  2. if (in_array('author', $classes)) {
  3. unset( $classes[array_search('author', $classes)] );
  4. }
  5. return $classes;
  6. });

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

  1. add_filter( 'body_class', 'replace_author_bob_name' );
  2. function replace_author_bob_name( $classes ) {
  3. // You have all the classes in $classes
  4. // Replaces author-bob with author-hello
  5. $new_classes = array();
  6. foreach($classes as $cls) {
  7. if ($cls == "author-bob") $new_classes[] = "author-hello";
  8. else $new_classes[] = $cls;
  9. }
  10. return $new_classes;
  11. }

展开查看全部

相关问题