在不带插件的编辑器中添加表格按钮

时间:2015-05-29 作者:user998163

我想在编辑器中添加“tablecontrol”。这就是我所尝试的:

function my_mce_buttons_1($buttons) {   

    $buttons[] = \'superscript\';
    $buttons[] = \'subscript\';
    $buttons[] = \'tablecontrols\';

    return $buttons;
}
add_filter(\'mce_buttons_3\', \'my_mce_buttons_3\'); 
这不起作用。非常感谢您的帮助。

拉尔斯

1 个回复
最合适的回答,由SO网友:Qaisar irfan 整理而成

我在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

结束