WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a plugin which updates the post's content in the Admin panel. For example, on the Edit post page, the user sees his draft content. If he clicks on a button from a meta box plugin, I want new HTML to be appended to the post content. Ideally without refreshing the page. Zemanta does this and I am trying to figure out the right method for achieving that effect.

NOTE: I am brand new to coding with Wordpress, so please let me know if/how my question needs to be clarified further.

share|improve this question
up vote 0 down vote accepted

This type of thing is most easily done from the TinyMCE editor through a plugin. Details of creating one using WordPress filters can be found here:


function myplugin_addbuttons() {
   // Don't bother doing this stuff if the current user lacks permissions
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )

   // Add only in Rich Editor mode
   if ( get_user_option('rich_editing') == 'true') {
     add_filter("mce_external_plugins", "add_myplugin_tinymce_plugin");
     add_filter('mce_buttons', 'register_myplugin_button');

function register_myplugin_button($buttons) {
   array_push($buttons, "separator", "myplugin");
   return $buttons;

// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
function add_myplugin_tinymce_plugin($plugin_array) {
   $plugin_array['myplugin'] = URLPATH.'tinymce/editor_plugin.js';
   return $plugin_array;

// init process for button control
add_action('init', 'myplugin_addbuttons');

The documentation on how to write the required editor_plugin.js file to perform your desired insert will be found on the TinyMCE site:




If you really must perform the insert by clicking a button in a meta box, then perhaps a close examination of the Zemanta plugin code will be helpful. Comment on this answer with a link to that plugin if you'd like some help with that.

share|improve this answer
Thanks marfarma. I went to the API and found the following function to give me all that I needed to keep making progress: tinyMCE.activeEditor.selection.getContent(); – Shaan Sep 26 '11 at 21:13
Please 'accept' the answer if your question was answered. It helps people, who find it later through search, to know that an answer was found. – marfarma Sep 26 '11 at 21:28
FYI: all links goes to 404 – Sisir Aug 29 '13 at 9:57
Fixed the tinymce links - apparently the site was restructured without page level re-directs. – marfarma Aug 29 '13 at 14:15

Your Answer


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.