How to add custom CSS (theme option) to TinyMCE?

Solution 1 This works as javascript solution: Example: tinyMCE.activeEditor.dom.addStyle(‘p {color:red; font-size:28px;}’); just open your js console and paste it for a quick test. To target a specific editor one should use: tinyMCE.getInstanceById(‘##editorID##’).dom.addStyle(‘p {color:red; font-size:28px;}’); This will inject the provided string into the editors iframe <head><style id=”mceDefaultStyles”></style> … Solution 2 Use wp_ajax as callback handler to … Read more

How to load wp_editor via AJAX

The main problem are the missing scripts. The scripts enqueued in _WP_Editors::enqueue_scripts() are never printed. The same is true for _WP_Editors::editor_js(). So you have to do that in your AJAX callback handler. I have written a demo plugin and put it on GitHub: T5 AJAX Editor. There is one class named Ajax_Editor. Its method render() … Read more

Creating a wp_editor instance with custom tinyMCE buttons

You pretty much had it, according to the description. Here’s what you might be looking for for instances 2 and 3 (for instance 1 you can leave the settings empty to get the default set of buttons): Instance 2: wp_editor( $distribution, ‘distribution’, array( ‘media_buttons’ => false, ‘textarea_rows’ => 8, ‘tabindex’ => 4, ‘tinymce’ => array( … Read more

Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1

The following small plugin creates a custom button inside line 1 of the WordPress TinyMCE Version 4, tested in WP Version 3.9-beta2. The plugin has var_dump included to understand the values. It’s also possible to add the button to other lines of the visual editor, only a other hook, like for line 2: mce_buttons_2. Result … Read more

Extra TinyMCE editor strips and tags?

I recently got this working. You should search and replace metaname with your meta box name. The key to maintaining formatting was using wpautop(); when saving the data. add_action( ‘add_meta_boxes’, ‘add_metaname_box’); add_action( ‘save_post’, ‘metaname_save’); function add_metaname_box() { add_meta_box( ‘metaname_id’, __( ‘metaname text’, ‘metaname_textdomain’), ‘metaname_custom_box’, ‘page’ ); } function metaname_custom_box() { global $post; wp_nonce_field( plugin_basename( __FILE__ … Read more

TinyMCE: adding CSS to format dropdown

You can not enhance the drop-down list formatselect. But you can enhance with the hook tiny_mce_before_init the second drop down styleselect, there is to hide in a default WordPress install. The documentation list all defaults and possibilities. inline – Name of the inline element to produce, for example “span”. The current text selection will be … Read more

Adding Custom Text Patterns in the WP 4.5 Visual Editor

Here’s a way to test the core patch #33300.6 by Andew Ozz, through a test plugin in WP 4.5.2, to try out the text pattern filter. Demo Here’s a strikethrough example using ~ $init[‘wpsetextpattern_inline_patterns’] = ‘{ strong: { start: “*”, end: “*”, format: “bold” }, strong2: { start: “**”, end: “**”, format: “bold” }, em: … Read more