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.

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.

  • 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. – Nabil Kadimi Oct 21 '16 at 1:34
  • @NabilKadimi, you are right. – mukto90 Oct 21 '16 at 16:15
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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