You can use media_sideload_image()
which will take a link to a file and upload it to the media library. You do need to pass it some kind of @Sumit points out in the comments you could pass $post_id
NULL
into the $post_id
field.
media_sideload_image(
$file_url,
$post_id,
$image_desc,
$return
);
If you need the uploaded image ID, take a look Tom J. Nowells answer using hooks
Related Posts:
- Choices for thumbnail image in a Facebook Link post
- How to disable generation of default image sizes for some custom post types?
- How to delete resized (cropped) image uploads and prevent future resizing?
- After Moving a Site to Another Domain, All Images Are Lost
- Disable image attachment links
- Prevent image upload unless exact size
- Use Media upload in custom widget on wordpress 3.5
- Way to force media uploader use custom image size
- Get FaceBook Friend Count [closed]
- add_image_size creating lots of images (of various sizes)
- How can I add the “Use as featured image” to a custom metabox?
- Image resize with image url
- How to increase media image scale limit?
- How to upload image without post ID using the new media uploader?
- Add suffix to filename of uploaded images
- Uploading an image as featured image from frontend form
- How to upload images from my directory into my wordpress?
- Adding a “most liked post” box, based on facebook ranking?
- Why images/photos after being uploaded to my wordpress site get slightly blurry?
- Images uploading to wrong directory after changing to multisite
- Metabox with multiple fields added by user and upload box
- How to stop unlink images when remove a site or user
- Restrict Image Uploads to a Certain File Type
- Rename media files generated during upload
- add_image_size() to crop images into squares?
- Combining media queries with image sizes
- RSVP form for Facebook events from a WordPress post?
- WordPress comments and Facebook comments
- How to remove Geo Tagging on image uploads, but not other EXIF data?
- Add Image Size for one Media Category Only
- Problem uploading images
- How to Create an Image Upload Box for Custom Posts?
- Taxonomies image
- Handling image uploads without thickbox
- How to preserve exact formatting when copy pasting from Facebook into WordPress (or elsewhere)?
- Disable all resizing and compression
- Posting to Facebook via WordPress – 500 Internal Error
- Loose images in uploads folder
- having issue while uploading An error occured in the upload. Please try again later
- Convert uploaded GIF to non animated image automatically
- Upload multiple images to a Woocomerce product
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- How to replace images?
- How can I echo og:video url, if the post has video content?
- using media_sideload_image with a file from theme directory
- Facebook preview Open Graph Object Debugger
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Blank upload.php page
- Upload image without media-upload [duplicate]
- Tinymce and uploading local pictures
- FB Comments box post to wall?
- Unable to upload images to the Media Library. Getting this erron on the console wp-admin/async-upload.php 403 (Forbidden)
- Original image not saving?
- WordPress automatically adds links to uploaded images
- Website Preview Graphic for WordPress Site
- No post image when pasting link into Facebook
- Images give 404 after changing default domain
- Create a post from every image in my media gallery
- Resize uploaded original images to a minimum automatically
- WordPress creating images if uploaded image is greater than 960px on one side?
- Convert canvas to image and upload image to server
- “This site is under development” when sharing on Facebook
- SFC Problem with the comment login
- Convert all uploaded PNG files to PNG-8 format
- WP / Facebook integration – recently read articles
- Making a parent directory writable by the server
- FB like adds WordPress install screen text to the wall
- How to display a warning when an uploaded image is too small?
- Large uploaded images not resizing?
- unable to write to the database while uploading images
- How to solve `Error getting remote image` in woocommerce rest api script?
- How to transfer the Facebook instance articles from one WordPress to another WordPress with same domain name?
- Unset image sizes before images are uploaded
- Loading and Referencing Images
- unsharp thumbnails after uploading image
- How to delete original image file after upload and resize
- An error has occurred during the upload process in wordpress version 5.3.2
- An error has occurred during the upload process in wordpress 5.3.2
- Hook for validating and rejecting frontend image upload
- Remove special characters from filenames
- Facebook sharing content problem
- Getting the Select and Crop Functionality Using Custom Fields
- How to make Facebook share the featuterd image from url on WordPress
- After I upload a file to library its name converted to dashes
- Only User Upload image Http Error
- See the all uploaded images of a user as an admin
- Broken Media Library
- Facebook posts on wordpress blog
- Utilise WP_Customize_Image_Control to only show image picker
- 3.5.x Theme Customize: Handling Custom Control Requests
- subscribe to wp through a Faceboo app
- Problem with Simple Facebook Connect
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Custom filename when pasting an image from clipboard
- Post on facebook when I publish blog
- get avatar from facebook graph [closed]
- Generate and upload screenshot as featured image for user-submitted post
- Custom Theme functions.php – Using add_settings_field and input type=”file” to set custom logo
- Can’t upload svg files in WordPress
- Random images from uploads folder and subfolder