Skip to content

WordPress media library not loading: fix the spinning grid

Learn how to fix a WordPress media library that is not loading, where the grid spins forever, stays empty or shows blank thumbnails. This guide shows you how to read the one request the grid depends on and trace it to a plugin, a firewall rule, a PHP error or missing files on a cPanel server.

This guide helps WordPress site owners and the admins who run their cPanel servers fix a media library that will not load. You open Media → Library and the grid spins forever, stays empty, or shows grey tiles where the thumbnails should be. The grid gets all its content from one background request to admin-ajax.php, the WordPress file that answers the admin’s background calls. Anything that spoils that reply stops the grid. You will read that reply, match what you see to one of four causes, and fix that cause instead of guessing.

What you’ll accomplish

  • Know in one minute whether the problem is the grid’s background request or the whole admin area.
  • Read the exact reply the grid received and sort it into one of four groups: blocked, crashed, polluted or valid.
  • Find the plugin, firewall rule, PHP error or missing file behind it, using logs and WP-CLI (the WordPress command-line tool).
  • End state: the grid loads its first page of items in under 2 seconds, with thumbnails, and the logs stay quiet.

Prerequisites

  • WordPress 6.0 or newer, and a login with the Administrator role.
  • Chrome, Edge or Firefox with developer tools (press F12 to open them).
  • Shell access as the site user, with WP-CLI run from the WordPress folder. The commands assume the site lives in ~/public_html.
  • For the firewall step, root access to WHM (the cPanel server’s admin panel) or a hosting provider who can read the server’s error log for you.
  • A staging copy is best for the plugin test in step 5. If you only have production, use the Health Check plugin’s troubleshooting mode, which changes the site for your session only.

If uploading files fails with the message “HTTP error”, that is a different request with different causes. Read HTTP error when uploading to the media library instead.

How it works

The media library has two views, and they load in different ways.

List view (upload.php?mode=list) is a normal admin page. PHP builds the whole table on the server and sends finished HTML (the page markup) to your browser.

Grid view sends a page with an empty grid. JavaScript in your browser then asks for the items by posting to /wp-admin/admin-ajax.php with action=query-attachments. WordPress answers with JSON (a plain-text data format) that starts with {"success":true,"data":[ and lists one entry per file, including thumbnail addresses. The browser then draws the tiles and loads each thumbnail image.

The grid only draws when that reply is clean JSON. A firewall block page, a PHP crash, a warning printed ahead of the JSON, or a stray blank line all break it. The browser console often shows nothing, so the grid keeps spinning with no visible error. This is why list view is such a useful test: it skips the background request entirely.

Decision tree that starts from a spinning media grid, checks whether list view loads, then sorts the admin-ajax.php reply into four groups with a likely cause and a fix for each

Step-by-step

1. Split the problem with list view. Open this address, with your own domain in place of example.com.

https://example.com/wp-admin/upload.php?mode=list

Expected: a table of your files with small thumbnails, loading in a few seconds. That means the database and the files are fine, and the problem is the grid’s background request. Go on to step 2.

If list view also fails with a blank page, a “critical error” message or a 500 error, the whole admin area is affected. Skip to step 4 and read the PHP error log first.

2. Read the grid’s reply in the Network tab. Switch back to grid view. Open developer tools, choose the Network tab, and type admin-ajax in the filter box. Reload the page. Click the request whose Payload tab shows action: query-attachments, then open its Response tab.

Expected: a status of 200 and a reply that starts like this.

{"success":true,"data":[{"id":4312,"title":"hero-banner","filename":"hero-banner.jpg",

Compare what you see with this list. Each line points to a later step.

  • Status 403, or an HTML page mentioning “Not Acceptable”, “Forbidden” or a challenge: a security rule blocked the request. Go to step 6.
  • Status 500, 502 or 503, or an empty reply: PHP stopped before it finished. Go to step 4.
  • Status 200, but the reply starts with <br />, “Warning”, “Deprecated” or a blank line: something printed text ahead of the JSON. Go to step 4, then step 5.
  • Status 200 with clean JSON, but the grid stays empty or the tiles are grey: the reply is fine. Look at browser scripts (step 5) or missing thumbnails (step 7).
  • Status 400 with a reply of 0: WordPress did not see you as logged in. See Troubleshooting.

3. Replay the request from a terminal. A terminal replay lets you test fixes without clicking through the admin each time. In the Network tab, right-click the query-attachments request and choose Copy as cURL. Paste it into a terminal, add -s -i | head -c 400 to the end of that same line, and press Enter. The result looks like the example below. The copied command carries your login cookie, so treat it like a password and do not share it.

# the copied command, shortened here, with the addition at the end
curl 'https://example.com/wp-admin/admin-ajax.php' -H 'cookie: ...' --data-raw 'action=query-attachments&...' -s -i | head -c 400
HTTP/2 200
content-type: application/json; charset=UTF-8
...
{"success":true,"data":[{"id":4312,"title":"hero-banner",

You should see the same status and first characters as in the browser. If the replay works but the browser does not, suspect a browser extension such as an ad blocker. Test in a private window with extensions turned off.

4. Read the PHP error log. On cPanel, the PHP error log is usually a file named error_log in the folder of the script that failed. The grid’s request runs from wp-admin, so look there first.

tail -n 30 ~/public_html/wp-admin/error_log
ls ~/logs/ | grep php.error

If your server uses PHP-FPM (the PHP process manager), errors may land in ~/logs/ in a file ending with .php.error.log instead. For a clearer record, turn on WordPress’s own debug log and keep messages off the screen.

wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_DEBUG_DISPLAY false --raw
Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'true'.

Reload the grid, then read the log.

tail -n 20 ~/public_html/wp-content/debug.log

What the lines mean:

  • Allowed memory size of 134217728 bytes exhausted means PHP ran out of memory at 128 MB (134217728 bytes). Go to step 8.
  • PHP Fatal error or Uncaught TypeError followed by a path in wp-content/plugins/<plugin-folder>/ names the plugin that crashed. Update it or deactivate it with wp plugin deactivate <plugin-folder>.
  • PHP Warning or PHP Deprecated lines point to the code that polluted the reply. With WP_DEBUG_DISPLAY now false, these no longer reach the JSON, so reload the grid and check whether it works. Report the warning to the plugin’s author as well.

If the reply still starts with a blank line and the log is quiet, a PHP file is printing whitespace. The usual culprits are a byte order mark (BOM, three invisible bytes some editors put at the start of a file) or blank lines after a closing ?> tag. These commands list candidate files.

grep -rl $'\xEF\xBB\xBF' --include='*.php' wp-content/plugins wp-content/themes wp-content/mu-plugins wp-config.php
grep -rlzP '\?>\n\s+\z' --include='*.php' wp-content/plugins wp-content/themes wp-content/mu-plugins

No output means no candidates were found. Any file listed is worth opening. Remove the BOM by saving it as “UTF-8 without BOM”, and delete the blank lines after the final ?>.

5. Find a conflicting plugin or theme. On production, install the Health Check & Troubleshooting plugin and turn on troubleshooting mode. It disables plugins for your session only, while visitors still see the normal site. Then turn plugins back on one at a time until the grid breaks.

On staging, WP-CLI is faster. Save the list of active plugins first, so you can restore it exactly.

wp plugin list --status=active --field=name > ~/active-plugins.txt
wp plugin deactivate --all
Success: Deactivated 23 of 23 plugins.

Reload the grid. If it now loads, a plugin is the cause. Turn on the first half of the list and test again.

wp plugin activate $(head -n 12 ~/active-plugins.txt)

If the grid breaks, the culprit is in those 12. If not, it is in the rest. Keep halving until one plugin remains, then restore everything.

wp plugin activate $(cat ~/active-plugins.txt)

If the grid still spins with every plugin off, test the theme. Run wp theme list to see which default themes are installed, then activate one, for example wp theme activate twentytwentyfour. Must-use plugins and drop-ins stay active through all of this, so list them with wp plugin list --status=must-use and wp plugin list --status=dropin.

For a clean JSON reply with an empty grid, also open the Console tab. A red Uncaught TypeError naming a file in a plugin folder points straight at the plugin.

6. Check for a ModSecurity or firewall block. ModSecurity is the web application firewall many cPanel servers run, and some of its rules dislike the grid’s request. As root, search the server’s error log.

grep -i modsecurity /etc/apache2/logs/error_log | grep admin-ajax | tail -n 5
[client 203.0.113.10] ModSecurity: Access denied with code 403 (phase 2). ... [id "941160"] ... [uri "/wp-admin/admin-ajax.php"]

Write down the number after id on your own server, since 941160 is only an example. WHM shows the same hits under Security Center → ModSecurity Tools. On LiteSpeed Enterprise, also check /usr/local/lsws/logs/error.log. Turn off only that rule, and only for this file. Create the file below, with your cPanel user and domain in place of <user> and <domain>.

# /etc/apache2/conf.d/userdata/ssl/2_4/<user>/<domain>/modsec.conf
<LocationMatch "/wp-admin/admin-ajax.php">
    SecRuleRemoveById 941160
</LocationMatch>

Put the same file under userdata/std/ if the site also answers on plain HTTP. Then rebuild and restart the web server.

/usr/local/cpanel/scripts/rebuildhttpdconf
/usr/local/cpanel/scripts/restartsrv_httpd

On LiteSpeed, run /usr/local/lsws/bin/lswsctrl restart afterwards. If the site sits behind Cloudflare, a challenge reply carries the header cf-mitigated: challenge. Find the matching entry in Cloudflare’s security events and add a narrow exception for /wp-admin/admin-ajax.php, rather than turning off the firewall.

7. Fix missing thumbnails and upload paths. Grey tiles with clean JSON mean the thumbnail images failed. In the Network tab, filter by Img. A 404 means the thumbnail file is missing, and a 403 means the server refuses to serve it. Recreate missing sizes with WP-CLI.

wp media regenerate --only-missing --yes
Found 412 images to regenerate.
...
Success: Regenerated 412 of 412 images.

For a 403, check permissions. Folders should be 755 and files 644. The commands below fix both.

find wp-content/uploads -type d -exec chmod 755 {} +
find wp-content/uploads -type f -exec chmod 644 {} +

After a migration, check that WordPress points at the right folder. The upload_path option should be empty unless you moved uploads on purpose.

wp option get upload_path
wp eval 'print_r( wp_upload_dir() );'

basedir should be a real folder on this server, such as /home/<user>/public_html/wp-content/uploads. An old path from the previous host means upload_path is stale. Clear it with wp option update upload_path ''. The regenerating thumbnails guide covers large regeneration jobs.

8. Raise the memory limit. Large libraries, big image metadata and heavy plugins can exhaust memory during the grid request. In cPanel, open MultiPHP INI Editor, choose the domain, and set memory_limit to 256M. Then let WordPress use it.

wp config set WP_MEMORY_LIMIT 256M
wp config set WP_MAX_MEMORY_LIMIT 256M

WP-CLI runs with its own PHP settings, so trust the byte count in the web error log, not the command line. If the log still shows exhaustion at 256 MB, a plugin is using far too much memory, and step 5 will find it.

Validate it works

Run through these checks in order.

  1. Replay the request from step 3. The reply starts with HTTP/2 200 and {"success":true,"data":[.
  2. Open Media → Library in grid view with an empty cache (Ctrl+Shift+R, or Cmd+Shift+R on a Mac). Tiles and thumbnails appear in under 2 seconds.
  3. Scroll to the bottom and click Load more. The next page appears.
  4. Open a post, click Add Media or an Image block’s Media Library button, and confirm the same grid loads there.
  5. Confirm the logs stayed quiet during those tests.
tail -n 5 ~/public_html/wp-content/debug.log
tail -n 5 ~/public_html/wp-admin/error_log

No new lines with today’s time means you are done. Leave WP_DEBUG_DISPLAY set to false. Turn WP_DEBUG back off with wp config set WP_DEBUG false --raw once the site is stable.

Troubleshooting

The reply is 0 with status 400. WordPress did not recognize your login on that request. This often happens when the site address differs from the admin address, for example www against no www, or http against https. Compare wp option get home and wp option get siteurl, make them match, then log out and back in.

Admins see the grid, but editors get {"success":false}. The grid requires the upload_files capability. A role-editor plugin may have removed it. Check with wp cap list editor | grep upload_files, and restore it with wp cap add editor upload_files.

Every plugin is off and the grid still spins. Check must-use plugins, drop-ins such as object-cache.php, and the theme, as in step 5. Also flush the object cache with wp cache flush, since a stale cached value can break the query.

The grid breaks only after scrolling to certain dates. One damaged file entry can crash PHP while WordPress prepares it. The fatal error in step 4 usually names the function. Find the item in list view, then run wp media regenerate <attachment-id> --yes to rebuild its data, or delete that item if the file is gone.

It works in one browser and not another. An extension is blocking admin-ajax.php, or the browser holds old admin scripts after an update. Test in a private window, then clear that browser’s cache.

When this is the wrong approach

If the grid loads but takes 20 seconds because the library holds tens of thousands of files, the problem is scale, and managing a 100k-item media library covers it. If uploads fail rather than the library view, use the upload error guide linked in Prerequisites. If your media lives in cloud storage through an offload plugin, missing thumbnails usually come from that plugin’s settings, so start with its own documentation. For every option of the regeneration command, see the WP-CLI media regenerate reference.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.