0

For example, we have some image on the external site: http://site.com/image.png

How do I upload this image to my wordpress as an image attachment by php?

Image should be copied to my uploads folder, post added, meta generated.

2

You can media_sideload_image() function to upload your files ex:

$upload = media_sideload_image( $url, $post_id );

or you can use a plugin like Cache Images which uploads all external images to your server as attachments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.