How to Upload an Image using WordPress REST API
In this tutorial, I am going to show three ways of how you can upload an image to a remote WordPress site using the REST API.
- In the first way, we’re going to do it using WordPress HTTP API functions:
wp_remote_post()orwp_remote_request(), - In the second way, I will show you how to do the same with cURL; why not?
- Finally, in the third way, I will show you an example of how to upload media with the WordPress REST API using JavaScript.
The methods here are also used by my Simple WP Crossposting plugin, because, you know, when you crosspost a post to another site with the REST API, you definitely need to copy its images as well, at least the featured image.
All right, let’s just dive into it.
How to Move WordPress Media Library to a New Site
In this tutorial, I am going to discuss different ways of moving the WordPress media library to a new site – both for multisite installations and standalone WordPress sites.
Get Featured Image in REST API
In this tutorial, I’d like to continue showing you some tips and tricks that can be useful when working with WordPress REST API, so I am going to show you two ways how you can get a featured image:
- If you know a featured image ID, you can always use the
/wp/v2/media/{$media_id}endpoint, I am going to discuss this method first. - Another story: if all you have is a post ID, and you need to get a featured image URL from it.
Using Global Product Images in WooCommerce Multisite
In this tutorial we’re going to talk about how to make WooCommerce display images from the main store (and we decide which store is going to be the main). The next question that you may have is how did that happen that you have the same products across different stores of your multisite network. And the reasons can be pretty much different, for example:
- Probably you’re using WooCommerce Multisite as a multilingual solution, so basically you have the same stores with the same products but in different languages.
- Or maybe you’re using my multisite crossposting plugin to publish your products to the other stores of your network.
And the whole idea of this tutorial is to prevent the product images from being duplicated to every sub-store uploads folders like /uploads/sites/2, /uploads/sites/3 and so on.
Get Attachment Alt Text, Caption, Description and Title Programmatically
Every time I work with WordPress attachments I always forget what is what, for example:
- What is the name of the alt text meta field?
- How to get an image caption programmatically?
Probably after publishing this tutorial I will never forget that again, but I really hope that it will be helpful for you guys.
So, the long story short, in this tutorial I am going to show you how you can get the following attachment data programmatically:

Let’s dive into it right now!
How to Create File Uploader on Checkout Page
In this tutorial I will show you step by step how to add a file uploader field to WooCommerce checkout page without any plugins.
2 Ways to Add SVG Support
Usually when I publish something on my blog I never use SVG images in my posts and in theory you would never need them too in your site content.
But the thing is that we’re not always using WordPress publishing tools (The Block Editor, Elementor etc) for content editing, sometimes we create landing pages with them. My decision to create a tutorial like this came to me when some of my customers who use my Simple WordPress Crossposting plugin tried to upload SVG images in Elementor and then to crosspost such articles to another site (which obviously didn’t have SVG support) using REST API.
When you try to upload an SVG icon to a WordPress website, you’re going to have an error like this in Media Upload:

Or if you try to upload it via REST API, then it will return 500 Server Error with the following response body: