I was pulling my hair out on this one, but I might have figured it out.
Try this (with jQuery):
if( ! tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden()) {
jQuery('textarea#content').val("[SHORTCODE]test[/SHORTCODE] ");
} else {
tinyMCE.execCommand('mceInsertRawHTML', false, "[SHORTCODE]test[/SHORTCODE] ");
}
Basically, you need to set the value of the textarea directly if the editor is hidden.
Related Posts:
- How to integrate a different (JavaScript) editor in WordPress?
- Reset Undo on the tinymce editor
- Instantiate TinyMCE via JS ( rather than PHP/wp_editor )
- Editing Source Code in WordPress
- TinyMCE Button to Insert Multiple Lines of Text?
- TinyMCE in a div / textarea on frontend?
- Want to have the Post editor remembering the last editing position
- How to wrap the content of the main tinyMCE editor with extra tags
- Instantiate TinyMCE via JS ( rather than PHP/wp_editor )
- How/Where is editor.min.js Added to the wp-admin Post Page?
- Add Item to Custom TinyMCE Menu
- Add tinymce dynamically via Javascript
- Listbox return wrong value in WordPress 3.9
- Using wp_editor in TinyMCE WindowManager dialog
- How to get value of selected page template in Gutenberg editor?
- Close TinyMCE plugin window on click away
- Make TinyMCE checkbox that returns a value instead of true/false
- TypeError: window.tinyMCE.execInstanceCommand is not a function
- Where is the WP auto-save draft JavaScript?
- How to set callback to execute after all the tinyMCE editors have been initialized?
- Popup box when Clicking on Insert into post button in wordpress
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- WP TinyMCE (Full + media ) – 4.8 JS Init Dynamicly
- Tinymce.js editor in Chrome?
- wordpress 4.4 upgrade visual editor bullets select for not selected elements
- How to reference TinyMCE body in my script
- Gutenberg consume wp-json data and reflect in frontend the content
- Make a script work within a page
- TinyMCE Javascript URL Question
- How to use WP switchEditors.switchto(this) JS function in your own script?
- Uncaught TypeError: switchEditors.switchto is not a function
- Using wp_editor() when not logged stopped working
- Dynamically write in editor with Javascript
- How to use value from modal tinymce windowManager?
- WordPress 4.2 mce-views migration guide?
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?
- add_attachment hook not firing on certain devices
- What does href expression do?
- Kadane’s algorithm explained
- How can I check for “undefined” in JavaScript? [duplicate]
- How can I reverse an array in JavaScript without using libraries?
- Download File Using JavaScript/jQuery
- Disabling and enabling a html input button
- TypeError: Cannot read property ‘then’ of undefined
- How to use php code in javascript
- How to read xml file contents in jQuery and display in html elements?
- using lodash .groupBy. how to add your own keys for grouped output?
- Uncaught ReferenceError: google is not defined when trying to use Google Places API without a map
- Why is window.showModalDialog deprecated? What to use instead?
- Should I use JSLint or JSHint JavaScript validation?
- How do I get the current time only in JavaScript
- Angular: conditional class with *ngClass
- Failed to compile. Module not found: Can’t resolve ‘react-router-dom’
- How to send an email from JavaScript
- MissingSchemaError: Schema hasn’t been registered for model “User”
- React’s setState method with prevState argument
- How to measure time taken by a function to execute
- var.replace is not a function
- Uncaught TypeError: Cannot read property ‘call’ of undefined at __webpack_require__
- This.props.dispatch not a function – React-Redux
- this vs $(this)
- How to open a URL in a new Tab using JavaScript or jQuery?
- How to sort an array of integers correctly
- Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.youtube.com !== http://localhost:9000
- How can I check whether a radio button is selected with JavaScript?
- JavaScript button onclick not working
- Ajax success function
- What is the equivalent of Java’s System.out.println() in Javascript?
- How can I exit from a javascript function? [duplicate]
- Object doesn’t support property or method ‘addEventListener’
- How to fix javascript .toFixed is not a Function error
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- WP 3.3 my rich text category editor toolbar is gone!
- Include Javascript as Plain (No file inclusion)
- Adding wp_ajax to a theme outside functions.php (on specific template page)
- What’s the handle for media.js?
- Disable HTML (Text) Tab in Post Editor
- Add custom HTML markup to Gutenberg RichText
- Enqueue scripts all over but not in single.php
- Multiple media uploader buttons target only one input on the same page
- TinyMCE 4 remove/add attributes for all images
- Prevent update_checkout from firing mid-typing
- Adding Code into Theme Customizer Header
- How to move core js files into the footer
- Suddenly extra hex string in tags
- Retrieving data about comments and likes
- Including Styles and JS files to work ON my plugin interface
- Linking wp_enqueue can’t find the javascript file (adds “?ver=x.x.x” to the src)
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- Javascript working on jsfiddle but not wordpress site?
- Drodown list return issue
- Spans in gutenberg
- Get a default customizeAction text for a section using Customizer JS API
- Put dynamic Javascript in header after doing operations
- custom page url slug needs illegal ?id=1 for javascript
- Use one javascript variable into another javascript file
- How can I replace the built in WordPress editor?
- How to add a css class to postTitleWrapper in Gutenberg?
- Escaping inline JS correctly