Title: create webp with wp_insert_attachment
Last modified: March 10, 2023

---

# create webp with wp_insert_attachment

 *  Resolved [pienoz](https://wordpress.org/support/users/pienoz/)
 * (@pienoz)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/)
 * When I insert images with wp_insert_attachment, the .webp file is not created.
   How to make it automatically created?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [adamewww](https://wordpress.org/support/users/adamewww/)
 * (@adamewww)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16548145)
 * Our plugin and optimization would get triggered on wp_generate_attachment_metadata
   and wp_handle_upload hooks.
 *  Thread Starter [pienoz](https://wordpress.org/support/users/pienoz/)
 * (@pienoz)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16552775)
 * I’m using wp_generate_attachment_metadata . My code :
 *     ```wp-block-code
         $attach_id = wp_insert_attachment( $attachment, $file );
   
           require_once(ABSPATH . 'wp-admin/includes/image.php');
   
           $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
   
           wp_update_attachment_metadata( $attach_id, $attach_data );
       ```
   
 *  Plugin Support [adamewww](https://wordpress.org/support/users/adamewww/)
 * (@adamewww)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16555215)
 * Can you try with an image that you know will generate a WebP? Note that our plugin
   won’t generate a WebP if it isn’t smaller than the original (as that is the point).
   Is it possible that whatever you were adding via this was already small enough?
   Can you try uploading it manually and seeing if a WebP image is generated?
 *  Thread Starter [pienoz](https://wordpress.org/support/users/pienoz/)
 * (@pienoz)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16556756)
 * When i upload manualy this image, Webp image is not generated.
 * But when I run a mass optimization the Webp files are created.
 * ![](https://i0.wp.com/www.sudradio.fr/wp-content/uploads/2023/03/test.jpg?ssl
   =1)
 * ![](https://i0.wp.com/www.sudradio.fr/wp-content/uploads/2023/03/after.jpg?ssl
   =1)
 *  Plugin Support [adamewww](https://wordpress.org/support/users/adamewww/)
 * (@adamewww)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16562181)
 * That is odd, as it should work to generate a WebP when you upload the image. 
   Can you get a debug log for us:
    1. Go to the support tab and check the box for Debugging and save
    2. Click the link in the support tab that says ‘Clear log’ so we have a clean slate
    3. Try your upload process with a specific image
    4. Go back to the support tab and click the Download Log button
    5. Send that log over to us and the name of the image that you tried to upload
    6. Uncheck the debugging option and save.
 * You can post the results in a pastebin or you can email it over to us directly
   [https://ewww.io/contact-us/](https://ewww.io/contact-us/)
 *  Thread Starter [pienoz](https://wordpress.org/support/users/pienoz/)
 * (@pienoz)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16575196)
 * In fact the queue was blocked. After deleting it, it works

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘create webp with wp_insert_attachment’ is closed to new replies.

 * ![](https://ps.w.org/ewww-image-optimizer/assets/icon-256x256.png?rev=1582276)
 * [EWWW Image Optimizer](https://wordpress.org/plugins/ewww-image-optimizer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ewww-image-optimizer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ewww-image-optimizer/)
 * [Active Topics](https://wordpress.org/support/plugin/ewww-image-optimizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ewww-image-optimizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ewww-image-optimizer/reviews/)

## Tags

 * [webp](https://wordpress.org/support/topic-tag/webp/)

 * 6 replies
 * 2 participants
 * Last reply from: [pienoz](https://wordpress.org/support/users/pienoz/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/create-webp-with-wp_insert_attachment/#post-16575196)
 * Status: resolved