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
- How do I display a PDF thumbnail as a link to the PDF without uploading the image
- Featured Image add tab
- There’s a way to scale media (images) at 50%?
- Saving the pre-sanitized filename of an attachment as the Title or Caption
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- How to add a link in a image’s caption?
- How to display a shortcode caption somewhere other than the_content
- Frontend image uploading from edit profile page. (goldenapples)
- Image size filtering in Media uploader according to custom post type
- How to upload imagick resource to media in wordpress
- How to store media files in subdomain
- Automatically Add Caption in image
- Uploading images to Media Library fails with Memory Exhausted
- Edit image preview is not displayed
- Include captions
- How to set a Minimum Image Dimension for Uploading
- Multisite media library uploads broken images
- Animated Gif image not uploading correctly
- Find unused images?
- Is there a plugin or simple way to add a multiple images metabox to a post?
- How can I upload an image for background use using the Theme Editor in WordPress?
- XML-RPC: How to add media caption to uploaded image?
- Show media url immediately after upload in media uploader
- Site migration – some images not displaying in Media Library
- Migration to WP – Couldn’t load image
- How to open default wp image editor screen dynamically?
- add media button is not working
- an error occurred in the upload. please try again later (Maybe File Permission Issue)
- Auto delete attachments that are older than x days
- Set Maximum Width for an uploaded image
- Uploaded images not displaying in network site
- Omit image captions from get_the_content()
- Change image name during uploading sequentially
- How to limit the number of images displayed in the media window?
- Is it possible to enable the ‘Link To’ field under ‘Attachment Display Settings’ for a Featured Image?
- Image upload error?
- Random home page background images with caption text
- How to add “alt” attribute for image during upload at WP front-end?
- Upload images – Theme options
- How to change image’s author via a function when using GravityForms uploader? [closed]
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- WordPress PHP custom function is causing 500 Internal Server Error Connection Timeout
- Can’t upload Images to WordPress – Error 500 Response
- Post-processing of the image failed
- WordPress 4.4.2 upload give error, can’t write is upper directory allowed to be written
- How to trigger “wp_handle_upload_prefilter” filter when uploading an image programatically?
- Change wordpress default upload path to another domain
- Broken images in media library
- Images are not getting uploaded
- Unable to delete images in Media Library
- How to regularly backup and update WordPress website with lot of images?
- Zip all (original) images from media gallery
- Assigning image to Post-Type won’t work anymore: exceeded time?
- Assign one featured image to multiple posts?
- Set padding for all content except images and few more elements
- Upload button in metabox not working
- Upload unnattached image from frontend
- How to automatically convert images to WebP on WordPress?
- How to get WordPress to resize images for srcset?