0

I want to add a button to TinyMCE editor, which opens Media Uploader of WordPress. I have used wp_editor(). Here is my code-

$editor = array(
    'textarea_name' => 'message',
    'media_buttons' => false,
    'textarea_rows' => 8,
    'quicktags'     => false,
    'drag_drop_upload' => true,
    'tinymce'       => array(
        'paste_as_text'                 => true,
        'paste_auto_cleanup_on_paste'   => true,
        'paste_remove_spans'            => true,
        'paste_remove_styles'           => true,
        'paste_remove_styles_if_webkit' => true,
        'paste_strip_class_attributes'  => true,
        'toolbar1'                      => 'bold italic | superscript subscript | bullist numlist | forecolor backcolor | link unlink | image media | visualblocks undo redo code',
        'toolbar2'                      => '',
        'toolbar3'                      => '',
        'toolbar4'                      => ''
        ),
    );

wp_editor( '', 'message', $editor );

I want an icon to be shown here- enter image description here

How do I do this? Thanks in advance.

2 Answers 2

2

Still not an easy in WordPres. you will have to create an MCE editor plugin that uses the WordPress media uploader.

An easier workaround is to create a very simple MCE editor plugin that added an icon who's only purpose will be to trigger a click on the 'Add Media' button. And that button;remove the media_buttons parameter from your wp_editor() arguments so that the button is shown, but then you hide it with CSS.

3
1

I recommend just enabling the built-in media button by setting:

'media_buttons' => true

It will place the button above the toolbar but it's a very simple solution.

2
  • 1
    It doesn't answer the question but +1 for the practical answer, note that media _buttons is true by default, so he only has to remove it, but he did it in purpose, he wants a button in the tool bar, just like he asked. Commented Oct 21, 2016 at 1:34
  • @NabilKadimi, you are right.
    – mukto90
    Commented Oct 21, 2016 at 16:15

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.