Php 将自定义Post要素图像设置为og:image

Php 将自定义Post要素图像设置为og:image,php,wordpress,facebook-graph-api,Php,Wordpress,Facebook Graph Api,我正在尝试将特色图像设置为og:image 我尝试了各种方法和插件(Yoast),但发现很难理解这一点 问题是,它根本没有拾取特征图像,而是拾取内容中的图像 这是我的当前页面代码,用于单个博客文章。这是我在Facebook上分享博客文章而不是内容图片时需要得到的部分 <div class="image-wrapper"> <?php if( get_field('featured_image') ): ?> <?php $featur

我正在尝试将特色图像设置为og:image

我尝试了各种方法和插件(Yoast),但发现很难理解这一点

问题是,它根本没有拾取特征图像,而是拾取内容中的图像

这是我的当前页面代码,用于单个博客文章。这是我在Facebook上分享博客文章而不是内容图片时需要得到的部分

<div class="image-wrapper">
        <?php if( get_field('featured_image') ): ?>
        <?php $featuredImage = get_field('featured_image'); ?>
        <img rel="image_src" src="<?php echo $featuredImage['url']; ?>" alt="">
        <?php else: ?>
        <img src="http://lorempixel.com/842/458/?rand9" alt="">
        <?php endif; ?>
</div>

“alt=”“>
当一篇博客文章的内容中没有任何图像时,它会做这种奇怪的事情,然后它会拾取功能图像和侧边栏中的图像。我还运行了Facebook调试器,但它同样只拾取内容图像

我确实找到了这段针对特写图片的片段,但我有一种感觉,因为我的是一篇自定义文章,它可能不会被选中

<meta property="og:image" content="<?php $post_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large'); echo $post_thumbnail[0]; ?>" />

设法找到了答案

<meta property="og:image" content="<?php $featuredImage = get_field('featured_image');  echo $featuredImage['url']; ?>" /