Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改Wordpress中TinyMCE的设置_Php_Html_Wordpress_Tinymce - Fatal编程技术网

Php 更改Wordpress中TinyMCE的设置

Php 更改Wordpress中TinyMCE的设置,php,html,wordpress,tinymce,Php,Html,Wordpress,Tinymce,我有一句话: 'paste_remove_spans': True, 我想用它来阻止TineMCE自动向粘贴到编辑器中的文本添加 我知道如何更改wordpress编辑器的布局/按钮,如下所示: function change_mce_options( $init ) { $init['theme_advanced_blockformats'] = 'p,address,pre,code,h3,h4,h5,h6'; $init['theme_advanced_disable'] = 'for

我有一句话:

'paste_remove_spans': True,
我想用它来阻止TineMCE自动向粘贴到编辑器中的文本添加

我知道如何更改wordpress编辑器的布局/按钮,如下所示:

function change_mce_options( $init ) {
 $init['theme_advanced_blockformats'] = 'p,address,pre,code,h3,h4,h5,h6';
 $init['theme_advanced_disable'] = 'forecolor';
 return $init;
}
add_filter('tiny_mce_before_init', 'change_mce_options');

但我似乎不知道如何添加这个新规则。我是否也需要为此设置过滤器?

您只需将代码修改为:

function change_mce_options( $init ) {
  $init['theme_advanced_blockformats'] = 'p,address,pre,code,h3,h4,h5,h6';
  $init['theme_advanced_disable'] = 'forecolor';
  $init['paste_remove_spans'] = true;
  return $init;
}
add_filter('tiny_mce_before_init', 'change_mce_options');

另外,请确保通过禁用/重新启用主题或插件来清除缓存。

它不再工作了

但我找到了有效的解决方案:

更改tinyMCEPreInit变量:例如,当我只想显示H3和时:


jQuery(文档).ready(函数($){
tinyMCEPreInit.mceInit.post_editor.block_formats=“段落=p;标题3=h3”;
});

您只需在函数中添加一行:
$init['paste\u remove\u span']=true
来实现这一点。@KristerAndersson我尝试过这个,但它仍然在我粘贴到编辑器中的文本中添加了额外的
标记。这看起来很奇怪,你是否尝试过禁用/重新启用你的主题,我想这可能是缓存问题。@KristerAndersson这起作用了。它现在已停止添加随机的
。如果你添加你的评论作为回答,我会接受。你把这个Javascript放在哪里了?有很多选择,你可以把它放在页脚,或者作为脚本文件排队,或者把它放在特定模板的某个内联位置