Last active
August 1, 2016 20:08
-
-
Save FinnWoelm/78031e6287a0c8fe587cc869dff24162 to your computer and use it in GitHub Desktop.
Adding button to Wordpress TinyMCE Editor via Theme Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions.php | |
// ... | |
// add new buttons | |
add_filter( 'mce_buttons', 'myplugin_register_buttons' ); | |
function myplugin_register_buttons( $buttons ) { | |
array_push( $buttons, '|', 'custom_class'); | |
return $buttons; | |
} | |
// Load the TinyMCE plugin : editor_plugin.js (wp2.5) | |
add_filter( 'mce_external_plugins', 'myplugin_register_tinymce_javascript' ); | |
function myplugin_register_tinymce_javascript( $plugin_array ) { | |
$plugin_array['myplugin'] = get_stylesheet_directory_uri() . '/tinymce-plugin.js'; | |
return $plugin_array; | |
} | |
// ... | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tinymce-plugin.js | |
(function() { | |
tinymce.PluginManager.add( 'myplugin', function( editor, url ) { | |
// Add Button to Visual Editor Toolbar | |
editor.addButton('custom_class', { | |
title: 'Insert CSS Class', | |
cmd: 'custom_class', | |
image: url + '/icon.png', | |
}); | |
// Add Command when Button Clicked | |
editor.addCommand('custom_class', function() { | |
alert('Button clicked!'); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment