I have added a custom button to the tinymce to insert my shortcodes, but I have so many and I want to make a splitbutton instead and I can’t figure how. Anyone can help. Here’s the code that I’ve used to create the normal button:
in functions.php :
/**
Hook into WordPress
*/
add_action('init', 'onehalf_button');
/**
Create Our Initialization Function
*/
function onehalf_button() {
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
return;
}
if ( get_user_option('rich_editing') == 'true' ) {
add_filter( 'mce_external_plugins', 'add_plugin' );
add_filter( 'mce_buttons', 'register_button' );
}
}
/**
Register Button
*/
function register_button( $buttons ) {
array_push( $buttons, "|", "onehalf" );
return $buttons;
}
/**
Register TinyMCE Plugin
*/
function add_plugin( $plugin_array ) {
$plugin_array['onehalf'] = get_bloginfo( 'template_url' ) . '/js/tinymce_buttons.js';
return $plugin_array;
}
and in the custom plugin .js
// JavaScript Document
(function() {
tinymce.create('tinymce.plugins.onehalf', {
init : function(ed, url) {
ed.addButton('onehalf', {
title : 'One Half Column',
image : url+'/mylink.png',
onclick : function() {
ed.selection.setContent('[one_half]' + ed.selection.getContent() + '[/one_half]');
}
});
},
createControl : function(n, cm) {
return null;
},
});
tinymce.PluginManager.add('onehalf', tinymce.plugins.onehalf);
})();
I’ve found something here http://tinymce.moxiecode.com/tryit/listbox_splitbutton.php but can’t figure out how to implement it into WP.
Anyone can help? Thanks.
It should be pretty straight-forward, copy the relevant pieces of code from the page you linked to into your existing TinyMCE plugin, update a few strings… done!..
Start with this for your TinyMCE plugin JS and see how you get on..
If something doesn’t work please report back with as much info as possible, ie. what you tried, what the result was, what did happen, what didn’t … etc..
t31os answer is great. Just a side note: to obtain the path to the image add
right before
createControl: function...
and now you can use it inAssuming your icon is right next to the JavaScript for the TinyMCE plugin.