Add a select a class dropdown in tinymce

To achieve the dropdown styles we have to use the filter hook tiny_mce_before_init. This filter grants developers access to the TinyMCE settings array. The following example adds custom style options to an existing Style dropdown. add_filter( ‘tiny_mce_before_init’, ‘my_mce_before_init’ ); function my_mce_before_init( $settings ) { $style_formats = array( array( ‘title’ => ‘1/5 Block’, ‘block’ => ‘div’, … Read more

How to enable the content editor as a droppable target with jQuery-ui?

In the above example the following line: jQuery(“.myDiv”).find(“li”).each(function(){ should be: jQuery(“.keywords”).find(“li”).each(function(){ That should enable the list items to be dragged and dropped. To allow the items to be dropped on the TinyMCE textarea the following code works. $(‘#editorcontainer’).droppable({ drop: function(event, ui) { alert(‘dropped’); //NOW FIRES! //Dynamically add content tinyMCE.activeEditor.execCommand(‘mceInsertContent’, false, ‘New content.’); } });

Preserving tabs and line breaks in when switching from HTML to Visual Editor

Add to function.php add_filter(‘tiny_mce_before_init’, ‘tiny_mce_before_init’); And function tiny_mce_before_init: function tiny_mce_before_init($init) { $init[‘setup’] = “function(ed) { ed.onBeforeSetContent.add(function(ed, o) { if ( o.content.indexOf(‘<pre’) != -1) { o.content = o.content.replace(/<pre[^>]*>[\\s\\S]+?<\\/pre>/g, function(a) { return a.replace(/(\\r\\n|\\n)/g, ‘<br />’); }); } }); }”; return $init; } http://core.trac.wordpress.org/ticket/19666 – it’s known bug, there is workaround but not fix tabs only new line … Read more

Close TinyMCE plugin window on click away

You asked the question a long ago but I was looking for something similar and found a solution. Enqueue an admin side script on post edit screens(where we have tinyMCE). Then use the code below: (function($) { ‘use strict’; $(document).ready(function() { $(document).on( ‘click’, ‘#mce-modal-block’, function() { tinyMCE.activeEditor.windowManager.close(); }); }); })(jQuery); This way you can close … Read more

Set tinymce direction to rtl

In wordpress, the editor will support and will be in RTL by default if you install it in an rtl language, for example, if you install wordpress with the hebrew UI the editor will be rtl by default. The problem is if you install the hebrew UI but change your profile to use the English … Read more

Is there a way to remove the default css from TinyMCE?

You should be able to remove these by hooking into the mce_css filter in your functions.php file: add_filter(“mce_css”, “my_remove_mce_css”); function my_remove_mce_css($stylesheets){ return “”; } I haven’t tested this but it should work. You might want to echo out the value of $stylesheets before you return nothing just to see what else is coming through – … Read more

Insert wp_editor on front-end with AJAX?

So, after doing some more digging, I answered my own question by “connecting the dots”, so to speak. There’s a lot of bits and pieces of info on this topic on StackOverflow and StackExchange, but none of them really answered my question. So here is the full working code to loading a wp_editor instance with … Read more

Sortable WYSIWYG editor

I pointed you to my work in chat, but for any other user, I have solved repeatable, sortable tinyMCE editors (as best as I could) and have the code available on github. Specifically, the JS script which includes a section on how to disable tinyMCE on the start of a sortable move and re-enable it … Read more

Show dialog box in TinyMCE plugin and use WordPress php functions in it

Instead of requireing admin.php you just can use WP built-in ajax functionality, even if it’s not ajax in this case. Add a hook add_action(‘wp_ajax_my_plugin_function’, ‘my_plugin_function_callback’); Create your output function (callback) function my_plugin_function_callback() { // do stuff } Call it this way instead of: file : url + ‘/box.php’, you should be able to use the … Read more