I’m trying to add some custom JS functionality to the default “post” editing screen that depends upon TinyMCE being instantiated and ready to rock. If I try to make the changes before TinyMCE is set up, I (obviously) receive JS errors.

Without needing to modify any core files, and ideally using JS/jQuery events alone (i.e. not PHP/WP hooks/filters or polling with JS’ setInterval()), is there a way to detect when TinyMCE is ready?

2 Answers
2

Unless your WP version is truly ancient, you should be able to use the tinymce-editor-init event triggered on editor init by “wp-includes/js/tinymce/plugins/wordpress/plugin.js”, eg (assuming your script is loading after jQuery):

jQuery( document ).on( 'tinymce-editor-init', function( event, editor ) {
    // Blah.
});

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *