1

I need to determine if the page/post editor is in Visual or Text mode. I also need to determine when this changes.

Does WordPress provide some kind of functionality for doing this? I am writing some JS that requires this information.

2 Answers 2

3
  1. To determine what mode the editor is currently in, you can use the getUserSetting('editor') in JavaScript, which returns either "html" or "tinymce".

  2. To determine when the editor mode is switched, you can use the jQuery click event handler on the #content-tmce and #content-html elements, which are the editor type switching buttons:

    jQuery( '#content-tmce' ).click( function() { // Visual editor selected } );

    jQuery( '#content-html' ).click( function() { // Text editor selected } );

Bear in mind that these click events will always be triggered when you click on the buttons; when you click on the "Visual" button for example, the event will be triggered regardless whether the current mode is "Visual" or "Text". If you need to, you could easily tackle that by storing the previous state yourself.

3
  • Quick and dirty, but it will probably work. I'm going to give it a try. Thank you for your feedback.
    – user52790
    Commented Jun 6, 2014 at 22:03
  • It is a little quick and dirty, but then again, that's how WordPress actually handles the Visual Editor modes itself. It's the prettiest way available, I believe. By the way, if it works, please mark the answer as "Accepted".
    – engelen
    Commented Jun 7, 2014 at 15:24
  • Yeah, I intended on accepting the answer. Seems to be what I was looking for. Thanks.
    – user52790
    Commented Jun 8, 2014 at 2:42
0

You could check tmce-active:

var editor = $('.tmce-active').val() != '' ? 'Text' : 'View';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.