I wanted to get a list of all WordPress themes installed, together with their meta info (e.g. name, status, author etc) using WordPress REST api. I also wanted to be able to activate any theme via my API client.
I’ve gone through this documentation but I didn’t find any relevant end-point.
Is it possible at this moment?
1 Answer
You can write your own endpoint and use wp_get_themes
to get a list of themes via that. Here is a simple one:
add_action( 'rest_api_init', function () {
//Path to rest endpoint
register_rest_route( 'theme_API/v1', '/get_theme_list/', array(
'methods' => 'GET',
'callback' => 'theme_list_function'
) );
});
// Our function to get the themes
function theme_list_function(){
// Get a list of themes
$list = wp_get_themes();
// Return the value
return $list;
}
Now you can get a list of your themes by accessing http://example.com/wp-json/theme_API/v1/get_theme_list
.
I wouldn’t suggest activating/deactivating themes via API. It can totally mess up things, such as activated widgets.