How can I add a button to quicktags-toolbar?

I would like to add a button to this toolbar, right of “fullscreen”:

enter image description here

Read More

The button should add this: „“

If text is selected, it should get around the text, like this: „selected text“

How can I add such a button to the ed_toolbar (class: quicktags-toolbar)?

Related posts

Leave a Reply

2 comments

  1. Try adding the following code in your function.php

    add_action( 'admin_footer-post-new.php', 'wpse_64665_add_quick_tag' );
    add_action( 'admin_footer-post.php',     'wpse_64665_add_quick_tag' );
    function wpse_64665_add_quick_tag() { ?>
        <script type="text/javascript">
            edButtons[edButtons.length] = new edButton( '„“', '„“', '„', '“', '' );
        </script><?php
    }
    
  2. The new, recommended way to add buttons to the toolbar is via the Quicktags API. Furthermore the site GenerateWP provides a handy code generator, which for this example creates the following:

    // Add Quicktags
    function custom_quicktags() {
        if ( wp_script_is( 'quicktags' ) ) {
        ?>
        <script type="text/javascript">
        QTags.addButton( 'fancy_quote_button', '„“', '„', '“', '"', 'Fancy quotes', 9 );
        </script>
        <?php
        }
    }
    add_action( 'admin_print_footer_scripts', 'custom_quicktags' );
    

    Note also that QTags also allows you to call JavaScript from buttons; the simplest example given is:

    QTags.addButton( 'my_id', 'my button', my_callback );
    function my_callback() { alert('yeah!'); }