TinyMCE编辑器formatselect中如何添加代码code项?

沃德普拉斯 发布于 3年前 分类:WordPress

我想在TinyMCE编辑器formatselect中添加代码code项,自带的只有段落p、各级标题h1-h6以及pre,我想要加入代码<code></code>标签,这样可以用highlight使代码高亮。

4个回复

  • ttt5

    我帮你查查文档

  • ttt5
    /**
     * Change the block formats available in TinyMCE.
     *
     * @link http://codex.wordpress.org/TinyMCE_Custom_Styles
     *
     * @param array $init Default settings to be overridden.
     *
     * @return array The modified $init array.
     */
    function cdils_change_mce_block_formats( $init ) {
    	$block_formats = array(
    		'Paragraph=p',
    		'Heading 1=h1',
    		'Heading 2=h2',
    		'Heading 3=h3',
    		'Heading 4=h4',
    		'Heading 5=h5',
    		'Heading 6=h6',
    		'Preformatted=pre',
    		'Code=code',
    	);
    	$init['block_formats'] = implode( ';', $block_formats );
    
    	return $init;
    }
    add_filter( 'tiny_mce_before_init', 'cdils_change_mce_block_formats' );
  • ttt5

    上面代码数组里的段落p、各级标题、预格式化和代码code可以根据你自己的需求进行增减

  • ttt5

    代码加到主题或者插件functions.php里应该就可以了