Fixing the 'function (){if(c){var a=c.length...' Error in Regenerate Thumbnails
Content
If you've landed here, you've likely encountered a frustrating and cryptic error message while trying to regenerate your WordPress thumbnails. The error often appears as a long, garbled string of JavaScript code, like this:
function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
This message is not helpful, and the regeneration process either fails completely or stops prematurely. This is a common issue reported by many users of the 'Regenerate Thumbnails' plugin. Based on community reports and troubleshooting, here’s what this error usually means and the most effective ways to resolve it.
What Causes This Error?
The garbled JavaScript code is a red herring. It is not the actual error. This text appears when the plugin's AJAX request—the process that communicates with your server to regenerate each image—receives an invalid response. Instead of receiving a clean JSON response with a success or error message, the plugin receives malformed data, often the output of a hidden PHP error or server limitation. The plugin then incorrectly tries to process this invalid data as JavaScript, resulting in the confusing code snippet.
The underlying causes for this invalid server response are typically one of the following:
- PHP Memory Exhaustion: Your server runs out of allocated PHP memory while trying to process a large, high-resolution image.
- Image Size Limitations: The physical dimensions of your images (e.g., wider than 2400px) exceed your server's processing capabilities.
- File Permission Issues: The WordPress application does not have write permissions to the
wp-content/uploads/directory and its subfolders, preventing it from creating new thumbnail files. - PHP Error Reporting: A warning, notice, or fatal error from another plugin, your theme, or WordPress core is being outputted and interrupting the AJAX response.
- Image Processing Library Conflicts: Issues with the server's GD or ImageMagick libraries can cause the image resizing function to fail silently.
How to Fix the Regenerate Thumbnails Error
Try these solutions in order, from the most common and easiest to implement to the more advanced.
1. Increase PHP Memory Limit
This is the most common fix. You can try to increase the memory available to PHP by adding the following line to your wp-config.php file, just before the line that says /* That's all, stop editing! Happy publishing. */.
define( 'WP_MEMORY_LIMIT', '256M' );
If this does not work, you may need to contact your web hosting provider and ask them to increase the memory_limit setting in the server's php.ini file.
2. Check and Fix File Permissions
WordPress needs permission to write to your uploads folder. The correct permissions are usually:
- Folders (Directories): 755 or 775
- Files: 644 or 664
You can adjust these permissions using an FTP client or your hosting provider's file manager. Warning: Avoid using 777 permissions, as this is a security risk.
3. Enable Debugging to Find the Real Error
To see the actual PHP error that is causing the invalid response, you need to enable WordPress debugging. Edit your wp-config.php file and make sure the following lines are present and set to these values:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
After enabling this, run the 'Regenerate Thumbnails' process again. This will force any errors to be written to a log file called debug.log in your wp-content/ directory. Check this file for the specific error message, which will give you a clear direction for your next step (e.g., a specific plugin conflict or a memory error).
4. Check for Plugin or Theme Conflicts
Temporarily disable all other plugins besides 'Regenerate Thumbnails'. If the process works, reactivate your plugins one by one to identify which one is causing the conflict. Some users have specifically reported conflicts with image optimization plugins like reSmush.it. If you identify a conflicting plugin, you may need to configure it or find an alternative.
Also, try switching to a default WordPress theme (like Twenty Twenty-One) to rule out an issue with your current theme.
5. Force the Use of the GD Library
Some users have resolved this issue by forcing WordPress to use the GD image editing library instead of ImageMagick. You can do this by installing a helper plugin like Default to GD.
6. Process Images in Smaller Batches
If you have thousands of images, the process can time out. The 'Regenerate Thumbnails' interface allows you to regenerate images one by one from the Media Library. Try processing a few smaller, recently uploaded images first to see if the error persists. If it works for single images, the issue may be related to server timeouts on long-running processes.
When All Else Fails
If you continue to experience issues after trying these steps, the problem is likely a strict server-level constraint imposed by your web host, such as a low process timeout or a very restrictive memory limit. Your best course of action is to contact your hosting provider's support, explain the issue, and ask if they can adjust these settings for you.
Remember, the garbled JavaScript is just a symptom. The solution almost always involves adjusting your server environment to handle the resource-intensive task of image processing.
Related Support Threads Support
-
JS error when regenerating single imagehttps://wordpress.org/support/topic/js-error-when-regenerating-single-image/
-
İ have a problem with Regenerate Thumbnailshttps://wordpress.org/support/topic/i-have-a-problem-with-regenerate-thumbnails/
-
Problem with errors displayhttps://wordpress.org/support/topic/problem-with-errors-display/
-
Errors when ran in WP 3.8.2https://wordpress.org/support/topic/errors-when-ran-in-wp-382/
-
Resize failure on some images with odd messagehttps://wordpress.org/support/topic/resize-failure-on-some-images-with-odd-message/
-
Errorhttps://wordpress.org/support/topic/error-701/
-
JavaScript errorhttps://wordpress.org/support/topic/javascript-error-137/
-
Regen Thumbnail doesn't workhttps://wordpress.org/support/topic/regen-thumbnail-doesnt-work/
-
function (){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.thttps://wordpress.org/support/topic/function-iflvar-tllengthfunction-itxeachtfunctiontnvar-rxt/
-
Error regenerating imageshttps://wordpress.org/support/topic/error-regenerating-images/
-
Does not work with all images–80% failure ratehttps://wordpress.org/support/topic/does-not-work-with-all-images-80-failure-rate/
-
[Plugin: Regenerate Thumbnails] Do not Workhttps://wordpress.org/support/topic/plugin-regenerate-thumbnails-do-not-work/
-
Regenerate Tumbnails Errorhttps://wordpress.org/support/topic/regenerate-tumbnails-error/
-
Regeneration is not workinghttps://wordpress.org/support/topic/regeneration-is-not-working/
-
Regenerate Failurehttps://wordpress.org/support/topic/regenerate-failure/
-
During the conversion javascript is displayedhttps://wordpress.org/support/topic/during-the-conversion-javascript-is-displayed/
-
Fails on every picture with an error message => solvedhttps://wordpress.org/support/topic/fails-on-every-picture-with-an-error-message/
-
Resize Failure – ERROR CODEhttps://wordpress.org/support/topic/resize-failure-error-code/
-
Error when trying to regenerate thumbnailshttps://wordpress.org/support/topic/error-when-trying-to-regenerate-thumbnails/
-
regenerate failure errorshttps://wordpress.org/support/topic/regenerate-failure-errors/
-
Several Errror messagehttps://wordpress.org/support/topic/several-errror-message/
-
Regenerate Thumbnails: Error getting a chunk of thumbnail IDs to process.https://wordpress.org/support/topic/regenerate-thumbnails-error-getting-a-chunk-of-thumbnail-ids-to-process/
-
WP 4.0 Issuehttps://wordpress.org/support/topic/wp-40-issue/
-
Failure after upgrading WP to 3.6https://wordpress.org/support/topic/failure-after-upgrading-wp-to-36/
-
[Plugin: Regenerate Thumbnails] Error while generating thumbnails for some fileshttps://wordpress.org/support/topic/plugin-regenerate-thumbnails-error-while-generating-thumbnails-for-some-files/
-
Regenerate image failurehttps://wordpress.org/support/topic/regenerate-image-failure/
-
Regenerate Thumbnails Plugin: SyntaxError: JSON.parse: unexpected character at lhttps://wordpress.org/support/topic/regenerate-thumbnails-plugin-syntaxerror-json-parse-unexpected-character-at-l/
-
[Plugin: Regenerate Thumbnails] resize failurehttps://wordpress.org/support/topic/plugin-regenerate-thumbnails-resize-failure/
-
Uncaught TypeError: Cannot read property ‘message’ of undefinedhttps://wordpress.org/support/topic/uncaught-typeerror-cannot-read-property-message-of-undefined/
-
Resize Failureshttps://wordpress.org/support/topic/resize-failures/
-
Regenerate thumbnails stop, can´t regenerate thumbnailshttps://wordpress.org/support/topic/regenerate-thumbnails-stop-cant-regenerate-thumbnails/
-
[Plugin: Regenerate Thumbnails] Odd PHP when failinghttps://wordpress.org/support/topic/plugin-regenerate-thumbnails-odd-php-when-failing/