0

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.

1 Answer 1

0

All the out-of-the-box API endpoints are documented quite well here:

https://developer.wordpress.org/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.com/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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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