将Custom Post功能图像设置为og:image


Set Custom Post feature image as og:image

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

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

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

这是我目前的网页代码为单一的博客文章。这是我在分享博客到脸书而不是内容图片时需要能够得到的部分。

<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>

当一篇博客文章的内容中没有任何图像时,它确实会做这种奇怪的事情,然后它会在侧边栏中获取功能图像和图像。我也运行了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']; ?>" /

我不得不调用自定义字段图像。