我试图在TinyMCE中的“块格式”下拉列表中添加一个项。我想添加一个名为“标题2灯光”的格式。
在里面functions.php
我添加此代码:
function theme_tiny_mce_before_init( $init ) {
$init[ \'block_formats\' ] = \'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 2 Light=h2-light;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Address=address;Pre=pre\';
return $init;
}
add_filter( \'tiny_mce_before_init\', \'theme_tiny_mce_before_init\' );
还有这个:function theme_after_wp_tiny_mce() {
?>
<script>
jQuery( document ).on( \'tinymce-editor-init\', function( event, editor ) {
tinymce.activeEditor.formatter.register( \'h2-light\', {
block : \'h2\',
classes : \'light\'
} );
} );
</script>
<?php
}
add_action( \'after_wp_tiny_mce\', \'theme_after_wp_tiny_mce\' );
这段代码成功地将“Heading 2 Light”添加到列表中,但当我单击它以应用格式时,会出现以下JavaScript错误:Uncaught TypeError: Cannot read property \'0\' of undefined
at Object.Eb [as applyFormat] (wp-tinymce.php?c=1&ver=4800-20180716:3)
at Lb (wp-tinymce.php?c=1&ver=4800-20180716:3)
at Object.toggle (wp-tinymce.php?c=1&ver=4800-20180716:3)
at d (wp-tinymce.php?c=1&ver=4800-20180716:3)
at mceToggleFormat (wp-tinymce.php?c=1&ver=4800-20180716:3)
at qg.execCommand (wp-tinymce.php?c=1&ver=4800-20180716:3)
at Hx.execCommand (wp-tinymce.php?c=1&ver=4800-20180716:3)
at wp-tinymce.php?c=1&ver=4800-20180716:5
at i.onselect (wp-tinymce.php?c=1&ver=4800-20180716:5)
at jg.c.fire (wp-tinymce.php?c=1&ver=4800-20180716:3)
TinyMCE JavaScript文件已缩小,因此很难调试。有人知道这是什么原因吗?