WordPress Troubleshooting

[Troubleshooting] WordPress “Add Media” Button Not Working

Since WordPress 3.7, more and more WP sites are experiencing this problem: “Add Media” Button Not Working

After clicking “Insert into Post button”, nothing happens !

Many topics on WordPress.org, but one of them actually tell the real cause and solutions.


With the help of Firebug, I was able to find the cause. Here are the steps:

Firstly, turn Firebug on, and insert an image.

Insert into Post button

After Clicking “Insert into Post” button, js error occurs.

WordPress Add Media Button Not Working

POST /wp-admin/admin-ajax.php

too much recursion                                cmb.js?ver=0.9.1 (line 128
    window.original_send_to_editor(html);

This error[too much recursion] shows that script “cmb.js?ver=0.9.1”  is preventing image from going into the Editor container.

Then I check the script url and it turned out to be a js file under theme folder.

So, the cause is : js conflicts.

  • Some [script within WordPress theme]  is in conflict with [the script inserting images into editor].
  • The bad script varies from theme to theme, it’s cmb.js in my theme.

Solution

You’d better send email to theme developer, asking him to solve this problem in next release.

If you can’t wait any longer, try disabling this script from loading.

To me, I found the related code under theme folder:

        wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', $cmb_script_array, '0.9.1' );
        wp_localize_script( 'cmb-scripts', 'cmb_ajax_data', array( 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), 'post_id' => get_the_ID() ) );
        wp_enqueue_script( 'cmb-timepicker' );
        wp_enqueue_script( 'cmb-scripts' );

 

To disable this script from loading, I commented one line:

        wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', $cmb_script_array, '0.9.1' );
        wp_localize_script( 'cmb-scripts', 'cmb_ajax_data', array( 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), 'post_id' => get_the_ID() ) );
       // wp_enqueue_script( 'cmb-timepicker' );
        wp_enqueue_script( 'cmb-scripts' );

 

That’s it!

The Add Media button is back to normal !

Cheers !

  1 Comment

  1. Jagadish (@jagadishsr)   •  

    Fucking cool man. Really cool. Of course I was fighting with WP these days and thought it might be a problem with my server. Anyhow, have to overhaul my JS to fix this. You gave this brilliant idea. Tell this to WP too so that they can woek on the next version fix. Kudos.

    Xie Xie . . . :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>