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?
- Dynamically creating charts of each row in an HTML table with chart.js
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Bind function
- Scroll to an element with jQuery
- Cannot open local file – Chrome: Not allowed to load local resource
- How do you reverse a string in-place in JavaScript?
- Uncaught TypeError: Cannot read property ‘length’ of undefined
- Python to JavaScript converter
- Fastest way to duplicate an array in JavaScript – slice vs. ‘for’ loop
- What is the difference between call and apply?
- AJAX response error: net::ERR_EMPTY_RESPONSE
- TypeError: Cannot Set property ‘onclick’ of null
- How would I call a javascript function in html?
- Mismatched anonymous define() module
- Function is not defined – Uncaught ReferenceError
- How do I include a JavaScript file in another JavaScript file?
- Textarea Auto height
- Angular 2 – Using ‘this’ inside setTimeout
- Download data URL file
- Discord error cannot read property ‘isFocused’
- onClick not working React js
- What language is JavaScript written in?
- How to output numbers with leading zeros in JavaScript?
- How to sort in mongoose?
- “Uncaught TypeError: a.indexOf is not a function” error when opening new foundation project
- How do you serve a file for download with AngularJS or Javascript?
- How can I cache image files locally with PhoneGap / Cordova?
- how to display a div triggered by onclick event
- Detect a finger swipe through JavaScript on the iPhone and Android
- JAX post error : Refused to set unsafe header “Connection”
- How to use onBlur event on Angular2?
- img onclick call to JavaScript function
- Bootstrap Collapse not Collapsing
- How to scroll to top of page with JavaScript/jQuery?
- Check if a JavaScript string is a URL
- How to include own css on wordpress tinymce editor?
- How to use Head JS with all enqueued scripts?
- How to add code to just before closing body tag
- How to get a jQuery script to run on a page?
- Switch to the library tab in the media uploader
- Customizer JS API: Defining control settings
- Customizer JS API: Adding Setting Dynamically Not Working
- Updata Metadata WP Rest API
- How to run JavaScript function in WooCommerce checkout?
- Insert “javascript:void(0);” into URL
- Render blocking issue in google page insight
- Adding nonce or hashes to inline scripts
- Open MediaUpload from external component in Gutenberg
- WordPress Media Library: Custom tab content displayed in “Media Library” tab
- Manually mark imported photo as selected in media library
- Call post-id from URL hash not working?
- Easy popups for wordpress?
- Why WordPress not using JSON_UNESCAPED_UNICODE by default?
- get_header() in backend – but keep JavaScript and CSS files
- Absolutely print script in footer
- How can I put this JavaScript into WordPress? [closed]
- Need help in fixing javascript in WordPress
- Uncaught TypeError: r is not a function
- How to show cities according to the state in Form using Javascript? [closed]
- Redirect to homepage if attmpting to leave intranet [closed]
- Twenty seventeen theme dropdown menu issue
- Unserialize WP_Options options programatically?
- javascript errors on mobile browser, not on desktop
- Loading 2 Different Version of JS files [closed]
- Adding react app to an existing wordpress website