个性化阅读
专注于IT技术分析

WordPress可视编辑器中的自定义样式不会将类应用于链接元素

点击下载

因此, 我为可视化编辑器设置了自定义样式, 如下所示:

// Registers an editor stylesheet for the theme.
function wpdocs_theme_add_editor_styles() {
    add_editor_style( 'editor-styles.css' );
}
add_action( 'admin_init', 'wpdocs_theme_add_editor_styles' );

// Callback function to insert 'styleselect' into the $buttons array
function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;
}
// Register our callback to the appropriate filter
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );

// Callback function to filter the MCE settings
function my_mce_before_init_insert_formats( $init_array ) {
    // Define the style_formats array
    $style_formats = array(
        // Each array child is a format with it's own settings
        array(
            'title' => 'Button', 'classes' => 'button', 'wrapper' => true, ), );
    // Insert the array, JSON ENCODED, into 'style_formats'
    $init_array['style_formats'] = json_encode( $style_formats );

    return $init_array;

}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );

问题#1为什么这种样式没有在链接” a”元素中添加” button”类?与” inline =>’span'”参数一起使用时效果很好, 但是将类直接应用于link元素更为简洁。我不想用span类乱七八糟的代码。

问题#2当我选择” mce_buttons_1″而不是” mce_buttons_2″时, 下拉列表未显示在第一行tinymce行中。由于原生下拉菜单, 我不能选择第一行吗?

问题#3实际上, 我希望将自定义样式添加到本机下拉列表中。那可能吗?我找不到有关如何执行此操作的任何资源。

谢谢! /杰普


#1


我找到了一种方法, 你应该首先将自定义样式应用于简单文本, 然后添加带有链接btn的链接, 然后编辑器将保留你的类。

赞(0)
未经允许不得转载:srcmini » WordPress可视编辑器中的自定义样式不会将类应用于链接元素

评论 抢沙发

评论前必须登录!