I've added a shortcode button in the TinyMCE editor in the page/post pages that opens up a Thickbox form.

The button is working; it opens up the thickbox form like it should. However my stumbling point is getting the value BACK to the TinyMCE editor and closing the thickbox.

This is the code I'm using to display the button and opening Thickbox

ed.addButton('aesloop', {
            title: 'Adds a loop of recent posts with specific parameters to the page.',
            image: url+'/../img/shortcodeloop.png',
            onclick: function(){
                tb_show('Test', 'admin-ajax.php?action=aes_ajax_test');

which calls this function

add_action('wp_ajax_aes_ajax_test', 'aes_ajax_test');
function aes_ajax_test(){
    // echo the form

At the end of the form there will be a button that is supposed to take all the data and turn it into a shortcode.

My question is:

How do I get data from this thickbox upon a button press BACK to the TinyMCE editor and then close the thickbox?

I've done a lot of searching but I can't find proper documentation on Thickbox and can't find any on shortcodes and thickbox forms as well.

EDIT: I have tried using window.send_to_editor and tb_remove but I might have used these wrongly

1 Answer 1


Okay so I spit through some existing themes I have to try and figure out how to achieve this. If anyone is reading this, this is how I did it:

In the onclick function of the TinyMCE I called the ajax form and then inside the form I added some javascript that uses the

tinyMCE.activeEditor.execCommand('mceInsertContent', 0, output);

command to put text back into the editor. This is ofcourse triggered by some sort of submit button.

Then I use


To close the thickbox again.

So essentially that would make the function look a bit like this:

add_action('wp_ajax_aes_ajax_test', 'aes_ajax_test');
function aes_ajax_test(){
    <script type="text/javascript">
                    tinyMCE.activeEditor.execCommand('mceInsertContent', 0, 'swag');
    echo '<button id="aes-submit">Submit Data</button>';
  • I would suggest to declare a variable var custom_active_tiny_mce; on the Script you are adding buttons.Than onClick store ed variable like : custom_active_tiny_mce = ed; And you can send Output to the Active TinyMCE even if user did not clicked on TextArea. Jan 11, 2013 at 20:27

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.