我在TinyMCE中使用此自定义按钮,我使用JavaScript
添加/开发此代码
查看此代码:
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 = \'[google-ad]\' + selected + \'[/google-ad]\';
} else {
content = \'[google-ad]\';
}
tinymce.execCommand(\'mceInsertContent\', false, content);
});
// Register buttons - trigger above command when clicked
ed.addButton(\'wpse72394_button\', {
title: \'Insert google ad code\',
cmd: \'wpse72394_insert_shortcode\',
image: url + \'/img/mobile_ads-32.png\'
});
},
});
// 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);
});
中TinyMCE编辑器的php短码寄存器
function.php
:
function google_ads( $atts, $content = null ) {
ob_start();
.....
return ob_get_clean();
}
add_shortcode( \'google-ad\', \'google_ads\' );
您必须阅读有关海关按钮加载项编辑器的文档:
https://codex.wordpress.org/TinyMCE_Custom_Buttons
并阅读本文:
http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182