Create js file button.js and add js directory and list-btn.png needed
(function() {
tinymce.create("tinymce.plugins.listbuttons_button_plugin", {
//url argument holds the absolute url of our plugin directory
init : function(ed, url) {
//add new button
ed.addButton("listbuttons", {
title : "Add Related post shortcode",
cmd : "listbuttons_command",
image : "images/list-btn.png"
});
ed.addCommand("listbuttons_command", function() {
var return_text = "[related]";
ed.execCommand("mceInsertContent", 0, return_text);
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {}
});
tinymce.PluginManager.add("listbuttons_button_plugin", tinymce.plugins.listbuttons_button_plugin);
})();
Add Code in Function.php
function enqueue_plugin_scripts($plugin_array){
$plugin_array["listbuttons_button_plugin"] = get_template_directory_uri() . "/js/buttons.js";
return $plugin_array;
}
add_filter("mce_external_plugins", "enqueue_plugin_scripts");
function register_buttons_editor($buttons){
array_push($buttons, "listbuttons");
return $buttons;
}
add_filter("mce_buttons", "register_buttons_editor");
function shortcode_button_script(){
if(wp_script_is("quicktags")){
?>
<script type="text/javascript">
QTags.addButton("list_buttons_shortcode","Add Related post shortcode",callback);
function callback(){
QTags.insertContent("[listbuttons]");
}
</script>
<?php
}
}
add_action("admin_print_footer_scripts", "shortcode_button_script");