解决方案1作为javascript解决方案:
示例:
tinyMCE.activeEditor.dom.addStyle(\'p {color:red; font-size:28px;}\');
只需打开js控制台并粘贴它即可进行快速测试。要以特定编辑器为目标,应使用:
tinyMCE.getInstanceById(\'##editorID##\').dom.addStyle(\'p {color:red; font-size:28px;}\');
这将把提供的字符串注入到编辑器iframe中
<head><style id="mceDefaultStyles"></style> ...
解决方案2使用wp\\u ajax作为回调处理程序,通过使用过滤器在编辑器init上添加动态样式
add_filter(\'tiny_mce_before_init\', \'dynamic_editor_styles\', 10);
function dynamic_editor_styles($settings){
// you could use a custom php file as well, I\'m using wp_ajax as
// callback handler for demonstration
// content_css is a string with several files seperated by a comma
// e.g. file1, file2, ... extend the string
$settings[\'content_css\'] .= ",".admin_url(\'admin-ajax.php\') ."/?action=dynamic_styles";
return $settings;
}
// add wp_ajax callback
add_action(\'wp_ajax_dynamic_styles\', \'dynamic_styles_callback\');
function dynamic_styles_callback(){
echo "p {color:red} h1{font-size:48px;}";
}