Hack to fix WordPress 3.5 Add Media issue when using Flexible Lightbox

July 25th, 2014

The problem: You cannot add media images on WordPress >= 3.5 when using the “Add Media” button in the WordPress editor. You are also using the Flexible Lightbox plugin, which is the root cause of the issue.

Here comes a dirty, quick, ugly and imperfect hack to the rescue:

  • Find your wp-admin/post-new.php file
  • Scroll to the end of the file, and modify the file as follow:


include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
include( ABSPATH . 'wp-admin/admin-footer.php' );


include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
        dataFilter: function (data, type) {
        var reg = /win.send_to_editor\('(.*?)'\);[\s]*/g;
        var matches = reg.exec(data);
            if (matches) window.send_to_editor(matches[1].replace(/\\"/g, "\"")
                                                         .replace("a href", "a class=\"lightbox\" title=\"\" href")
            return data;

include( ABSPATH . 'wp-admin/admin-footer.php' );

This should also serve as an example of code not to write.

Follow me @pierotofy and don't forget to