【问题标题】:How to prevent add_editor_style from running?如何防止 add_editor_style 运行?
【发布时间】:2020-03-23 15:10:33
【问题描述】:

我想知道如何使用我自己的functions.php 来阻止add_editor_style( $protocol.$universal_css_url ); 运行(所以我的意思是通过钩子或类似的东西)?

有没有办法禁用或删除它?喜欢:remove_editor_style( $protocol.$universal_css_url ); 那太好了!不幸的是,这段代码不起作用..

谢谢!

【问题讨论】:

  • add_editor_style 将样式表添加到全局 $editor_styles 数组变量中。您可以尝试清除该数组!?
  • 明确我的意思是从数组中删除不需要的样式表。
  • 啊太棒了!如何从 $editor_styles 数组中删除某些内容?

标签: php wordpress function plugins hook


【解决方案1】:

试试这个代码示例,这应该可以帮助您入门!?

function theme_remove_editor_styles() {
    // Get the global var
    global $editor_styles;
    // Get the item you want to move
    $entry_to_move = $editor_styles[4];
    // Remove a specific entry
    unset($editor_styles[4]);
    // Add the entry back to the beginning of the array
    array_unshift($editor_styles, $entry_to_move);
}
add_action('pre_get_posts', 'theme_remove_editor_styles', 100);

【讨论】:

  • 谢谢!我在打印的数组中看到,最后一个元素是我想要摆脱的元素。有没有办法将最后一个元素发送到数组的开头?那就更好了!
  • 我在上面编辑了我的答案。这应该将项目移动到开头。不过,您将不得不更改索引。
猜你喜欢
  • 2019-01-30
  • 2012-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 2011-04-12
  • 2018-11-11
相关资源
最近更新 更多