Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/f70677e2165161e5a9f307f1affecd4b to your computer and use it in GitHub Desktop.
Save FrancoStino/f70677e2165161e5a9f307f1affecd4b to your computer and use it in GitHub Desktop.
Shortcode Javascript for button TinyMCE
jQuery(document).ready(function($) {
tinymce.create('tinymce.plugins.wpse72394_plugin', {
init : function(ed, url) {
// Register command for when button is clicked
ed.addCommand('wpse72394_insert_shortcode', function() {
selected = tinyMCE.activeEditor.selection.getContent();
if( selected ){
//If text is selected when button is clicked
//Wrap shortcode around it.
content = '[p]'+selected+'[/p]';
}else{
content = '[p]';
}
tinymce.execCommand('mceInsertContent', false, content);
});
// Register buttons - trigger above command when clicked
ed.addButton('wpse72394_button', {title : 'Contenuto nascosto', cmd : 'wpse72394_insert_shortcode',
image: 'https://cdn.iconscout.com/icon/free/png-256/lock-1851239-1569128.png' }); // INSERT IMAGE
},
});
// Register our TinyMCE plugin
// first parameter is the button ID1
// second parameter must match the first parameter of the tinymce.create() function above
tinymce.PluginManager.add('wpse72394_button', tinymce.plugins.wpse72394_plugin);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment