Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/0b0db92851abc0494d0e57d858ecbab8 to your computer and use it in GitHub Desktop.
Save FrancoStino/0b0db92851abc0494d0e57d858ecbab8 to your computer and use it in GitHub Desktop.
Create button for insert shortcode into TinyMCE
<?php
// init process for registering our button
add_action('admin_init', 'wpse72394_shortcode_button_init');
function wpse72394_shortcode_button_init() {
//Abort early if the user will never see TinyMCE
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true')
return;
//Add a callback to regiser our tinymce plugin
add_filter("mce_external_plugins", "wpse72394_register_tinymce_plugin");
// Add a callback to add our button to the TinyMCE toolbar
add_filter('mce_buttons', 'wpse72394_add_tinymce_button');
}
//This callback registers our plug-in
function wpse72394_register_tinymce_plugin($plugin_array) {
$plugin_array['wpse72394_button'] = get_stylesheet_directory_uri() . '/shortcode.js';
return $plugin_array;
}
//This callback adds our button to the toolbar
function wpse72394_add_tinymce_button($buttons) {
//Add the button ID to the $button array
$buttons[] = "wpse72394_button";
return $buttons;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment