0

I am creating a wordpress plugin(backend activity, form submission) where Instead of inserting plain text, users need to add images and html texts so, I need to use wp_editor instead of form element. code for wp_editor I used below.

wp_editor( '', 'instructions', $settings = array('textarea_name' => 'instructions', 'textarea_rows' => '5') );

I can see "add media" button but, when I click on it, nothing (no media library pop up) appears however, if I go to Posts-> Add a new post and over here same the "add media" button poping up media library normally, where user can insert or select already uploaded image files.

1

I will assume that you are creating a custom admin page at ?page=add-quiz, in this case before calling the wp_editor function you also have to enqueue the CSS / Js files for it with the wp_enqueue_media() function.

So at the end you should have

wp_enqueue_media();
wp_editor( '', 'instructions', $settings = array('textarea_name' => 'instructions', 'textarea_rows' => '5') );

A clever way to do it would be inside an action like

function prefix_my_custom_admin_scripts() {
    wp_enqueue_media();
}
add_action('admin_enqueue_scripts', 'prefix_my_custom_admin_scripts');

Again assuming that you don't have this hook already.

  • it did not work . however, yes I guess there is something to do with wp_enqueue_media – Amit Bravo Aug 31 '16 at 6:15
  • 1
    I found out problem, this code was preventing add media popup , soon I removed it , things start working well. <!-- <script tst="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" src="<?php echo plugins_url('/js/jquery.min.js', FILE); ?>" type="text/javascript"></script> --> – Amit Bravo Aug 31 '16 at 7:17

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.