Adding
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
after
$attach_id = wp_insert_attachment( $attachment, $filename);
Fixed it.
Related Posts:
- How to generate thumbnails when needed only?
- No Thumbnails Generated
- How to Require a Minimum Image Dimension for Uploading?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Reject upload of wrong-sized images using the Media Uploader
- Create image formats with different qualities when uploading
- Which filters or actions to use after a media upload and delete?
- PNG with transparent background turns black when uploaded and resized
- Settings in ‘Media > Settings’ is ignored when inserting images
- There’s a way to scale media (images) at 50%?
- How to prevent upload of a multiple sizes of images
- How can I prevent uploading bmp image?
- Impose a Maximum Limit on Image height and width upload size
- Force wordpress to see uploads folder media
- Convert uploaded PNG to JPEG automatically
- add_image_size creating lots of images (of various sizes)
- resize images not crop
- Add suffix to filename of uploaded images
- How to link to the image editor’s Edit Image function?
- Front-end Image Upload with Preview – Is this Possible in WP?
- WordPress won’t generate image sizes for certain images
- Thumbnails produce unwanted gray pixels on white background [closed]
- Site icons with alpha channel for self-hosted WordPress blog network
- How can I receive the image id using the media box?
- Can I stop wordpress generating media sizes
- add_image_size() and uploading the exact size leaves 1×1 image in uploads
- WordPress Fancybox Resize Large Image
- Error uploading images (but the images are at the server!)
- How to generate thumbnails when needed only?
- WordPress Media Library showing wrong preview size?
- add_image_size adds size, but doesn’t upload if source resolution is same as resize resolution
- Original image not saving?
- Process uploads with phpThumb before generating thumbnails
- Resize existing library images
- Large image upload size (using timthumb.php
- Image resizing – TimThumb vs convert on upload?
- WordPress Bug on IIS ? Problem when uploading image on IIS 7
- When does WP resize an image file
- Stop image resizing in particular case – is that possible?
- Issue with images which have no sizes available
- How to resize attachement
- Best way to receive special images in posts
- Resize uploaded original images to a minimum automatically
- Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio
- Control resizing of uploaded images
- Images uploaded via Gutenberg image block are cropped
- Set default “Link CSS Class” in add media admin editor
- Images not aligning correctly
- Redimension thumbnail crop without creating new images
- get the post thumbnail returns the full size
- WordPress Image Resize fails without Error Message
- How to force attachment size for every post
- Media files exist in upload folder but not showing up
- How to upload SVG in WordPress 4.9.8?
- Adding a custom image upload size and making it selected by default?
- WP 3.3 > Still no option to enable automatic image overwrites?
- How to get all files inserted (but not attached) to a post
- Get attachment ID of author_meta image – Attachment Metadata
- uploading files to the uploads folder via ftp
- Delete images uploaded by ‘Subscriber’ role
- How to resize image on client-side before upload?
- http error when uploading media files
- How can I upload a csv file into WordPress?
- Hook or function to upload media via url
- wp_generate_attachment_metadata generates 503 Service Unavailable or 500 timeout errors
- Hook to get image filename when it is uploaded
- wp_enqueue_media() Will not load JS on the theme
- Upload images from one site to another in Multisite
- media_sideload_image with rewritten urls?
- How to set a contact forms total size limit
- All Images on wordpress site broken
- ‘Cheatin’ uh?’ Error When Attempting to Upload Images After 3.4 Update
- Media Gallery Upload photo incorrect way like glitch
- Alter the image, before save, of a particular image size
- Is it possible to use media_sideload_image to upload local files?
- How to switch to year/month directory structure format from a single folder
- How to edit attachment with media-upload.php?
- Uploaded image with non-english characters is named incorrectly in upload folder
- after migration, newly uploaded images won’t show up
- Cropping thumbnails to specific dimensions on front end post
- Double slash in upload URLs
- Unable to upload new file as a product
- Alter the image used for a user who has not uploaded a custom image yet
- Personalized Gallery what are my options?
- Some problems in custom widget
- Make inline uploader (plupload) on options page upload to a specific folder
- What is wrong with my wp_insert_attachment code?
- Set attachment category from file name on upload
- HTTP Error WordPress on IIS uploading image
- _d_improd_ directory in uploads breaking site images
- Where to add my code to auto attach images to existing products
- Drag and Drop Media Not Working in Windows 10 Edge Browser
- Exclude some photos in media library
- Upload more than one media files with a post
- How to handle image resize in media_handle_sideload?
- Image uploaded in media library, can only see it when I using the WP Edit Image feature. 404 when trying to view in browser
- Single file upload
- What does WordPress media uploader do to image files on upload?
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- Upload to a specific media folder created by FileBird Lite