Use wp_ajax
as callback handler to add dynamic styles on editor init by using a filter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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;}"; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.