1

i want to add the "tablecontrol" ty the editor. This is what I've tried:

function my_mce_buttons_1($buttons) {   

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

    return $buttons;
}
add_filter('mce_buttons_3', 'my_mce_buttons_3'); 

This does not work. Any help is appreciated.

Lars

1 Answer 1

2

i use this custom button for ad's in TinyMCE, i use JavaScript code to add/develop this one

look into this code:

    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);
 });

php shortcode register for TinyMCE Editor in function.php:

function google_ads( $atts, $content = null  ) {

    ob_start();

    .....

    return ob_get_clean();
}
add_shortcode( 'google-ad', 'google_ads' );

You must read documentation about customs button add in editor:

https://codex.wordpress.org/TinyMCE_Custom_Buttons

and also read this article:

http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182

4
  • Please do not answer with links only. Answers should be more than pointers to where someone finds an answer. Provide everything needed for an answer here on the page – with an edit. Thanks.
    – kaiser
    Commented Jun 1, 2015 at 6:26
  • 1
    Thanks for the tip @kaiser , next time i will provide more data about the question on the page. Commented Jun 1, 2015 at 6:33
  • You can still do that – with an edit to your answer (which will give you upvotes and therefore capabilities as well). Btw, your name sounds pretty much like mine :)
    – kaiser
    Commented Jun 1, 2015 at 6:44
  • now i update the answer for the custom button with code like a little example @kaiser. Commented Jun 1, 2015 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.