How can I speed up a slow loading media library?

I’m copying a previous answer here as I think it will help. What this will do is whenever the media library pops up, instead of showing all media for a given post it will filter down to only images attached to the post. You could paste this right into your functions file:

/**
 * Media Module - Only Show Images Uploaded To this Post
 */
function wpse222583_media_library_filter() { 
    ?>
      <script type="text/javascript">
        jQuery( document ).on( 'DOMNodeInserted', function() {
            jQuery( 'select.attachment-filters [value="uploaded"]' ).attr( 'selected', true ).parent().trigger( 'change' );
        } );
      </script>
    <?php 
}
add_action( 'admin_footer-post-new.php', 'wpse222583_media_library_filter' );
add_action( 'admin_footer-post.php', 'wpse222583_media_library_filter' );

The above doesn’t remove the filter from the media module so if you need to see all the media you can just change the filter while in the admin panel, this just presets it to only show attached media.

Media Library Filter Dropdown List

If this doesn’t work there’s a ton of other answers to this older question which I feel is related.

Leave a Comment