wordpress - 用于网站图标和徽标图像的 Wordpress REST API
问题描述
有人可以帮助我如何在 Wordpress rest api 中获取徽标和网站图标图像的端点吗?当我使用 http:// .... / wp-json / 端点时,我得到的标题或名称和描述没有图像链接?
解决方案
对于徽标,您需要将此函数添加到functions.php:
// wordpress api for logo extension
add_action( 'rest_api_init', 'add_logo_to_JSON' );
function add_logo_to_JSON() {
register_rest_field( 'post', 'page_logo_src', array( // post for where to register - page_logo_src is the name for api
'get_callback' => 'get_logo_src',
'update_callback' => null,
'schema' => null,
)
);
}
function get_logo_src( $object, $field_name, $request ) {
$size = 'full';
$custom_logo_id = get_theme_mod( 'custom_logo' );
$feat_img_array = wp_get_attachment_image_src($custom_logo_id, $size, true);
return $feat_img_array[0];
}
然后徽标在此处可用:http://your-domain/wp-json/wp/v2/posts
在page_logo_src
.
您可以使用此功能获取所需的任何 wordpress 数据,以供 favicon 使用get_site_icon_url
。
推荐阅读
- html - 仅在媒体屏幕中禁用浮动
- android - 用户以某种方式访问免费版中的专业版功能
- powerapps - MS Powerapps:Forall 与 Office365.SendEmail 结合使用
- javascript - 物化标签在 Laravel 中不起作用
- ios - 如何让 SnapKit 约束左右边缘?
- json - 是否可以使用 Python 在 JSON 中将日期写为 DateTime 格式而不将其转换为字符串
- python - Tensorflow: Tensor to numpy array conversion without running any session
- push-notification - 带有冒号 (:) 的 FCM 令牌在 Azure NH 中返回错误请求
- c++ - 按下一个产生中断的按钮即可调用多个函数
- java - Java Util SQL Parser 为正确的语句引发异常