Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted
  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.

share|improve this answer
    
Quick and dirty, but it will probably work. I'm going to give it a try. Thank you for your feedback. –  user52790 Jun 6 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 Jun 7 at 15:24
    
Yeah, I intended on accepting the answer. Seems to be what I was looking for. Thanks. –  user52790 Jun 8 at 2:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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