在用于社交共享的 WordPress 中,我使用的是 yoast seo 插件。现在根据客户要求,我需要为 og:image 设置条件,如下所示。
- 如果在 yoast 元框中为帖子/页面添加了图像,则显示该图像
- 如果 yoast seo 中没有图片,请检查帖子/页面中的特色图片
- 如果 yoast seo 和特色图像中没有图像,则显示设置中的一些图像。我如何知道图像是否上传到特定页面的 yoast 元框中并满足上述要求?我尝试了以下方法,但它只替换了 yoast 元框中的图像。
add_filter( 'wpseo_opengraph_image', 'ag_yoast_seo_fb_share_images', 10, 1 );
function ag_yoast_seo_fb_share_images( $img ) {
return ( $img && ! empty( $img ) ) ? $img : get_field( 'social_share_image', 'options' );
};