向MCE下拉工具栏添加自定义样式

时间:2012-10-26 作者:Anders Kitson

我正在使用以下代码在mce工具栏中添加样式下拉列表,我希望能够使用下拉列表添加h1元素,但我的代码不起作用,我尝试了几种不同的方法,但都不起作用,我得到了此代码表单here

add_filter( \'mce_buttons_2\', \'my_mce_buttons_2\' );
function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, \'styleselect\' );
    return $buttons;
}
//mce custom classes
add_filter( \'tiny_mce_before_init\', \'my_mce_before_init\' );

function my_mce_before_init( $settings ) {

    $style_formats = array(
        array(
            \'title\' => \'Button\',
            \'selector\' => \'h1\',
            \'classes\' => \'button\'
        ),
        array(
            \'title\' => \'h1\',
            \'block\' => \'h1\',
            \'classes\' => \'superHead\',
            \'wrapper\' => true
        ),
        array(
            \'title\' => \'Bold Brown\',
            \'inline\' => \'span\',
            \'styles\' => array(
                \'color\' => \'#481e07\',
                \'fontWeight\' => \'bold\'
            )
        ),
        array(
            \'title\' => \'Header\',
            \'inline\' => \'span\',
            \'styles\' => array(
                \'font-size\' => \'24px\'
            )
        )
    );

    $settings[\'style_formats\'] = json_encode( $style_formats );

    return $settings;

}

//mse custome classes
add_action( \'admin_init\', \'add_my_editor_style\' );

function add_my_editor_style() {
    add_editor_style();
}

1 个回复
SO网友:Brooke.

根据本教程,您缺少了整个第一步:

add_filter( \'mce_buttons_2\', \'my_mce_buttons_2\' );

function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, \'styleselect\' );
    return $buttons;
}

结束

相关推荐

如何将父主题的css文件出列?

我的父主题(Starkers)添加了一个我试图删除的CSS文件(我想改用@import,这样我可以更轻松地覆盖样式)。Starkers具有以下功能。php:add_action( \'wp_enqueue_scripts\', \'script_enqueuer\' ); function script_enqueuer() { wp_register_script( \'site\', get_template_directory_uri().\'/js/site.js