首页 > 解决方案 > style_loader_tag 过滤器正在转换特殊字符,即使禁用 wptexturize

问题描述

我正在使用 style_loader_tag 过滤器预加载一些 gfonts,问题是将所有“&”转换为“ 8;”。

我检查了我的函数,它正确输出了 html,所以我很确定是过滤器在做这个改变。

我尝试在该过滤器上禁用 wptexturize,但它不起作用。

remove_filter('style_loader_tag', 'wptexturize', 1);
add_filter('style_loader_tag', 'rubik_style_loader_tag_filter', 10, 2);
add_filter('style_loader_tag', 'wptexturize', 11);

我什至试过这个:

add_filter( 'run_wptexturize', '__return_false', 1 );

但是..还是什么都没有。

有什么建议吗?

标签: wordpresswordpress-theming

解决方案


您可以使用过滤器设置要跳过的 html 标记。

将跳过包含在标签 pre、code、kbd、style、script 和 tt 中的文本。可以使用 no_texturize_tags 过滤器更改此标签列表。

https://developer.wordpress.org/reference/hooks/no_texturize_tags/

add_filter( 'no_texturize_tags', 'disable_link_filter', 1, 1 );
function disable_link_filter($filter){
  $filter[] = "link"; //Add Link tag to the skip list
  return filter;
}

编辑:要转储所有过滤器挂钩,您可以使用以下功能

function print_filters() {
  global $wp_filter;
  print '<pre>';
  print_r( $wp_filter );
  print '</pre>';
}

要调用它,您可以使用

print_filters();

推荐阅读