There is this function:
get_header_image()
which can be called from within WordPress. Is there a way to access this externally, i.e. from the API? The use case might be a header for an external RSS feed, etc.
There is this function:
get_header_image()
which can be called from within WordPress. Is there a way to access this externally, i.e. from the API? The use case might be a header for an external RSS feed, etc.
Share Improve this question asked Jul 28, 2020 at 23:28 John DeeJohn Dee 5135 silver badges14 bronze badges1 Answer
Reset to default 0All the out-of-the-box API endpoints are documented quite well here:
https://developer.wordpress/rest-api/reference/
A quick look in the relevant places didn't turn up a way to get theme elements (although I might have missed it).
It's trivially easy to setup new API endpoints; here's a quick example you could pop into your funcitons.php to 'hard-wire' into that function to allow you to get the result returned in JSON at example/wp-json/themeelements/v1/header_image
:
add_action( 'rest_api_init', function () {
register_rest_route( 'themeelements/v1', '/header_image', array(
'methods' => 'GET',
'callback' => 'get_header_image',
) );
} );
(Note for me with a clean WP install and the twentytwenty theme with no images added this returns an empty string)