I wonder if this will work for you:
add_action( 'add_attachment', function( $attachment_id ){
$a = get_post( $attachment_id );
if ( is_object( $a ) && 'image' === substr( $a->post_mime_type, 0, 5 ) )
wp_insert_attachment( array( 'ID' => $a->ID, 'post_excerpt' => $a->post_content ) );
});
or with less queries:
add_action( 'add_attachment', function( $attachment_id ){
global $wpdb;
if( ! empty( $attachment_id ) )
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts
SET post_excerpt = post_content
WHERE ID = %d LIMIT 1", $attachment_id ) );
});
where the description (post_content
) is copied to the caption (post_excerpt
) when the add_attachment
is fired just after the attachment has been inserted (added).
Related Posts:
- Upload images to remote server
- Using Images in WordPress – Best Practices
- Media Upload Folder – how to manage
- How do i upload an image and return the image id?
- Restrict the number of images to upload per post
- How to add a media with PHP
- What’s the best “insert all images” plugin?
- Different upload path per file type
- Rename media files generated during upload
- HTML tags in WordPress image caption
- HTTP Error when uploading files above 7mb unless using GD Image Editor
- Change WordPress Media Manager
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- image in my post disappeared after I upload website to remote server
- Handling image uploads without thickbox
- How can I create more upload paths, like a post corresponding to a post title folder used to store images of the same product
- WordPress automatically downscaled images larger that original
- Ho to add “Create Slider” option to default “Add Media” popup?
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Change wp-content/uploads to uploads/%postname%/%image%
- Blank upload.php page
- Upload media only to DB
- Get images attached to a specific page
- Is there a way in WordPress to convert images to WebP without a plugin?
- Disable image rename on upload
- How can i identify media uploaded to my website that is not being used anywhere anymore?
- image URL changed in wordpress
- Serving Images from subdomain in wordpress
- User uploads image as “Featured Image” but WordPress resizes it?
- Profile image does not upload
- WordPress append -1 to the image name
- cant upload media/pictures to my wordpress site, cant upload anything to my database
- Upload error on localhost (at minimum, not yet tested online)
- unsharp thumbnails after uploading image
- Updated wordpress missing image upload area
- page displaying media caption shortcodes
- Missing Images in Uploads Directory (Server Only)
- Broken Media Library
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- Uploading media to wordpress API with C# HttpClient
- Each custom image size in custom upload directory?
- Adding a custom image upload size and making it selected by default?
- How to copy and paste a picture found on the web to wordpress easily
- Get attachment ID of author_meta image – Attachment Metadata
- Insert Images at Master Uniform Height
- upload featured image from front end using wordpress add media button
- How to Display an Image Uploaded through a Meta Box in a Template?
- HTTP Error when trying to upload image
- Media sizes aren’t being created – server config?
- Rename attachments during upload
- Drag images with caption in WP editor
- When Uploading JPEGs, Does WordPress Compress the Original Image?
- How to make programmatic image upload generate thumbnail and sizes?
- Best way to strip character entities (%20 etc)
- 3.5 media.editor: what is the event listener for choosing an image?
- How can I receive the image id using the media box?
- media_sideload_image with rewritten urls?
- How to set a contact forms total size limit
- All Images on wordpress site broken
- Multiple images with Media Uploader on front-end
- Removing height and width from images with a caption
- How to keep WP from recompressing Full Size images
- Turn off image captions in gallery view?
- Alter the image, before save, of a particular image size
- Missing a temporary folder.error when image is uploaded in admin Set temporary Directory – WordPress 5.2.2
- WP fails to upload files to media library, /wp-admin/async-upload.php 403 forbidden
- Add a background image for Custom Post Type archives page
- Show image crop window on image upload
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Set Maximum Width for an uploaded image
- Uploaded images not displaying in network site
- Omit image captions from get_the_content()
- How to limit the number of images displayed in the media window?
- How to get the Gallery form/section just like in Gutenberg block?
- after migration, newly uploaded images won’t show up
- How to use getimagesize() of image upload?
- How to change image’s author via a function when using GravityForms uploader? [closed]
- Alter the image used for a user who has not uploaded a custom image yet
- Allow users to upload multiple images to their profile
- How to join Caption AND Description Meta Fields as one combined-caption in Image Block
- Allow a specific user role I have created to only upload one image to his media library
- How to increase media image scale limit?
- Can’t upload Images to WordPress – Error 500 Response
- How to auto add image caption from image alt?
- Generate links on all images in posts – is there a hook?
- Run command to optimize images after they get uploaded to WordPress
- Where to add my code to auto attach images to existing products
- Set WordPress to Create different images format later, not during upload
- The most of the images don’t appear, although URLs are correct
- WordPress Media URLs?
- Add two images with Sweet Testimonials
- How to add a credit line to a photo caption
- Upload button in metabox not working
- Import existing image as a single post
- How do I change a Themes Header Image?
- Media upload error
- Delete all thumbnails & regenerate them?
- What does WordPress media uploader do to image files on upload?
- How To Convert External Image URLs To Own Website’s Uploaded Images Automatically?