【问题标题】:force linkedin to use custom thumbnail of wordpress post强制linkedin使用wordpress帖子的自定义缩略图
【发布时间】:2017-06-21 13:53:30
【问题描述】:

我在我的functions.php中使用它

  add_theme_support( 'post-thumbnails'); 
  set_post_thumbnail_size(); 

  add_image_size( 'post-thumb', 669, 272 );

在我的 single.php、home.php 和 archive.php.. 我在循环中使用它:

   <?php the_post_thumbnail('post-thumb'); ?>

现在,当我将帖子分享到linkedin 时,我使用了 669 x 272 尺寸的缩略图,但我想制作另一个自定义尺寸的缩略图,例如 180 x 110 大小 n 强制linkedin 使用该缩略图。

提前致谢。

【问题讨论】:

    标签: php wordpress linkedin


    【解决方案1】:

    您将需要使用 OpenGraph 标记来指定要从中提取的社交媒体网站的内容。 Documentation.

    OpenGraph 标签必须放在&lt;head&gt; 中。您可以通过在您的 functions.php 中添加类似这样的内容来实现这一点:

    function add_opengraph() {
        ?>
        <meta property="og:title" content="<?= get_the_title() ?>" />
        <meta property="og:image" content="<?= get_the_post_thumbnail_url( 'small-thumb' ) ?>" />
        <meta property="og:image:width" content="180" />
        <meta property="og:image:height" content="110" />
        <?php
    }
    add_action( 'wp_head', 'add_opengraph' );
    

    您当然需要像以前一样制作另一个缩略图大小。

    add_image_size( 'small-thumb', 180, 110 );
    

    您可以尝试调试的另外两件事:

    1. 尝试检查一个新页面,一个您以前没有测试过的页面。 LinkedIn 可能正在缓存您的旧图片。
    2. 您使用的是 HTTPS 吗?根据this commentLinkedIn 可能无法抓取 HTTPS 网址。

    【讨论】:

    • 我确实使用这个“小拇指”名称创建了另一个缩略图大小,但在浏览器源代码中它仍然显示前一个的高度。我的代码在functions.php中是这样的add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(); add_image_size( 'post-thumb', 669, 272, true ); add_image_size( 'small-thumb', 180, 110, true ); function add_opengraph() { ?&gt; &lt;meta property="og:title" content="&lt;?= get_the_title() ?&gt;" /&gt; &lt;meta property="og:image" content="&lt;?= get_the_post_thumbnail_url( 'small-thumb' ) ?&gt;" /&gt; &lt;?php } add_action( 'wp_head', 'add_opengraph' );
    • 您可以尝试使用 Facebook 的 OpenGraph 调试器来查看他们正在提取的图像吗? Link here.
    • 您还可以检查页面来源,看看您的帖子是否显示了 opengraph 标签。
    • 我安装了 Yoast SEO 插件。它覆盖了打开图形图像的高度。但是当我停用插件时,它现在显示 og 的高度和宽度。是的,它在打开的图表中显示标题和图像..但不包括元属性标签中的高度或宽度。
    • 您可以告诉 OpenGraph 图像的预期大小。我更新了我的答案。能否查看页面源代码,并确认 OpenGraph 图片的 url 是否正确?
    猜你喜欢
    • 1970-01-01
    • 2015-01-25
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多