When a file such as an image is uploaded, an optimized version is created with $saved = $editor->save($editor->generate_filename('name'));. This successfully writes the file to disk and the intermediate sizes are created too from the source/original image.

I'd like to add the optimized version to the array of sizes. I've tried the following but no additional size is added to the metadata array.

$metadata['sizes']['full'] = [];
$metadata['sizes']['full']['file'] = $saved['file'];
$metadata['sizes']['full']['width'] = $saved['width'];
$metadata['sizes']['full']['height'] = $saved['height'];
$metadata['sizes']['full']['mime-type'] = $saved['mime-type'];
$metadata['sizes']['full']['filesize'] = $saved['filesize'];

I've attempted $metadata['sizes'] = array('full' => $saved,); but again the 'full' size isn't added/appended to the list existing array.

How can I go about adding/pushing/merging it?

  • Is your code run inside of an action or filter? Please provide more details.
    – Caleb
    Jun 21 at 1:34
  • @Caleb, it runs with add_filter('wp_generate_attachment_metadata'
    – Motivated
    Jun 21 at 2:02

1 Answer 1


Although the suggested answer from admcfajn wasn't the solution to the problem/question, it did lead me to look explore it further. Thanks admcfajn.

Assuming you are using either the default intermediate e.g. thumbnail or custom sizes e.g. 320w and would like to include additional sizes such as full, you can use wp_update_attachment_metadata( $attachment_id, $metadata );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.