admin管理员组文章数量:1327965
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)
本文标签: optionsIs there a standard technique or API for getting the site header image
版权声明:本文标题:options - Is there a standard technique or API for getting the site header image? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225135a2436173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论