1 回答

TA貢獻(xiàn)1786條經(jīng)驗 獲得超11個贊
您可以使用Yoast SEO v14+ 中的Schema API調(diào)整圖像。
<?php
/**
* Changes url of Main_Image (ImageObject) Schema data.
*
* @param array $data Schema.org Main_image data array.
* @return array Schema.org Main_image data array.
*
* @link https://developer.yoast.com/features/schema/api#to-add-images-to-your-schema
*/
add_filter( 'wpseo_schema_main_image', 'example_change_wpseo_image' );
function example_change_wpseo_image( $data ) {
$attachment_ID = '123';
$img_src = wp_get_attachment_image_src( $attachment_ID, 'full' );
if (! empty( $img_src )){
$url = $img_src[0];
$data['url'] = $url;
}
return $data;
}
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報