Problems with Open Graph

时间:2014-10-17 作者:Andy Graziano

我准备把剩下的头发从我该死的脑袋里拔出来。我一辈子都搞不明白,当我通过WordPress 4.0的Publication进行分享时,Facebook为什么不会从帖子中提取特色图片,甚至是图片。

我在Yoast SEO中检查和取消检查了“插入og标签”,尝试了shareaholic,甚至将这些行硬编码到我的函数中。php(请参阅下面的代码)。

//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
  return $output . \' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"\';
}
add_filter(\'language_attributes\', \'add_opengraph_doctype\');
//Lets add Open Graph Meta Info
function insert_fb_in_head() {
  global $post;
  if ( !is_singular()) //if it is not a post or a page
    return;
  echo \'<meta property="fb:admins" content="480187318774482"/>\';
  echo \'<meta property="og:title" content="\' . get_the_title() . \'"/>\';
  echo \'<meta property="og:type" content="article"/>\';
  echo \'<meta property="og:url" content="\' . get_permalink() . \'"/>\';
  echo \'<meta property="og:site_name" content="Islanders Insight"/>\';
  if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
    $default_image="http://www.islandersinsight.com/wp-content/uploads/2014/08/BvlnJMzIUAEGHEu.jpg"; //replace this with a default image on your server or an image in your media library
    echo \'<meta property="og:image" content="\' . $default_image . \'"/>\';
  }
  else{
    $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'large\' );
    echo \'<meta property="og:image" content="\' . esc_attr( $thumbnail_src[0] ) . \'"/>\';
  }
  echo "
";
}
add_action( \'wp_head\', \'insert_fb_in_head\', 5 );
这是facebook页面:https://www.facebook.com/IslandersInsight

以下是帖子:http://www.islandersinsight.com/2014/10/new-york-islanders-vs-san-jose sharks赛前报道/

有人能帮忙吗?我正要开始用塑料刀割腕。

以下是调试器向我抛出的唯一错误:

推断属性应显式提供“og:url”属性,即使可以从其他标记推断出值。

推断属性应明确提供“og:title”属性,即使可以从其他标记推断出值。

推断属性应明确提供“og:description”属性,即使可以从其他标记推断出值。

推断属性应明确提供“og:image”属性,即使可以从其他标记推断出值。

这些是我单击“检查页面源”时看到生成的唯一OG标记:

<!-- OpenGraph Facebook Start -->
<meta property="og:title" content="New York Islanders vs. San Jose Sharks: Pregame Report" />
<meta property="og:description" content=" #479084605 / gettyimages.com When: Thursday October 16th, 2014 Where: Nassau Veterans Memorial Coliseum, Uniondale, NY Time: 7 p.m. TV: MSG+ (Howie Rose, Butch Goring) Radio: WRHU 88.7 FM (Chris King..." />
<meta property="og:image" content="http://www.islandersinsight.com/wp-content/uploads/2014/10/SharksatIsles-150x150.png" /> <!-- OpenGraph Facebook Ends -->
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="http://www.islandersinsight.com/xmlrpc.php" />
正如您所看到的,看起来有什么东西正在将我的特色图片缩小到150x150,尽管它的大小为1800x1200。

那是怎么回事?为什么调试器不向我抛出一个错误来提醒我这个事实呢?很明显,只是在黑暗中开枪而已。

1 个回复
SO网友:Seamus Leahy

这是因为你的标记无效,这导致Facebook认为meta 元素位于主体中。你可以通过running the page through W3C validator 这对于Facebook linter错误消息有意义:

您的页面在正文而不是标头中有元标记。这可能是因为HTML格式不正确,它们在解析树中的位置较低。请修复此问题,以便标记可用。

我怀疑这是你脑中所有的追踪代码。

<!-- Start DFP SETUP -->
  <script type="text/javascript"><!--
  //<![CDATA[
  (function() {
  var useSSL = \'https:\' == document.location.protocol;
  var src = (useSSL ? \'https:\' : \'http:\') + \'//www.googletagservices.com/tag/js/gpt.js\';
  document.write(\'<scr\' + \'ipt src="\' + src + \'"></scr\' + \'ipt>\');
  })();
  //]]>
  //--></script>
  <script type=\'text/javascript\' src=\'http://img.bnqt.com/lib/js/sdpdfphelper.js\'></script>
  <script type="text/javascript">
    googletag.pubads().enableSyncRendering();
    googletag.pubads().setTargeting("title", sdpTargeting.title)
                      .setTargeting(\'targetPaths\', sdpTargeting.targetPaths)
                      .setTargeting(\'fullPath\', sdpTargeting.fullPath)
                      .setTargeting(\'queryStr\', sdpTargeting.queryStr)
                      .setTargeting(\'domainName\', sdpTargeting.domainName);       
  </script>
  <!-- DFP SETUP end -->

<!-- Begin comScore Tag -->
<script>
  var _comscore = _comscore || [];
  _comscore.push({ c1: "2", c2: "6035223" });
  (function() {
    var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
    s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
    el.parentNode.insertBefore(s, el);
  })();
</script>
<noscript>
  <img src="http://b.scorecardresearch.com/p?c1=2&c2=6035223&cv=2.0&cj=1" />
</noscript>
<!-- End comScore Tag -->
将它们移到页面的最末尾,就在</body></html>.

结束

相关推荐