我在一个站点上的所有帖子中添加了开放式图形元数据,然而,当我尝试在Facebook上粘贴帖子链接时,图形元数据没有加载。
然后,当我插入URL时into the debugger / linter, 无论是在调试器中还是在Facebook上正常发布时(之前不起作用),它都可以工作。
这个问题似乎addressed in the past, in this Stack Overflow question. 然而,这个问题与Rails环境有关。
在这个问题上,应用程序无法同时处理多个http请求。通过在后台使用延迟响应(delayed\\u response)处理所有Facebook API请求,问题得以解决。
在运行Wordpress的PHP环境中,我可以用什么最简单的方式来完成这个或类似的任务,从而(希望)解决我的问题?
**我在这篇文章中没有包括一个示例链接,因为只要用户通过调试器运行它,它就会正常工作*
编辑-帖子页面中的元标记示例:
<meta property="og:title" content="Budget proposal good news for Ontario drivers - AdvocateDaily.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://build.advocatedaily.com/wp-content/uploads/2013/04/Stacey-Stevens_Colour_NEW_2012-e1354206636925-150x150.jpg" />
<meta property="og:url" content="http://advocatedaily.com/2013/05/budget-proposal-good-news-for-ontario-drivers/" />
<meta property="og:description" content="A provincial budget proposal to reduce auto insurance premiums by an average of 15 per cent is good news for Ontario drivers, but should not come at the cost of benefits available under the policy, says Toronto personal injury lawyer Stacey L. Stevens. “In response to this announcement, the Insurance Bureau of Canada (IBC) predicts the [...]" />
<meta property="og:site_name" content="Advocate Daily" />
插入wp\\U头的PHP:
add_action(\'wp_head\', \'add_fb_open_graph_tags\');
function add_fb_open_graph_tags() {
if (is_single()) {
global $post;
if(get_the_post_thumbnail($post->ID, \'thumbnail\')) {
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_object = get_post($thumbnail_id);
$image = $thumbnail_object->guid;
} else {
$image = get_template_directory_uri()."/images/advocatedaily-avatar.png";
}
//$description = get_bloginfo(\'description\');
$description = og_excerpt( $post->post_content, $post->post_excerpt );
$description = strip_tags($description);
$description = str_replace("\\"", "\'", $description);
?>
<meta property="og:title" content="<?php the_title(); ?> - AdvocateDaily.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="<?php echo $image; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:description" content="<?php echo $description ?>" />
<meta property="og:site_name" content="<?php echo get_bloginfo(\'name\'); ?>" />
<?php }
}
function og_excerpt($text, $excerpt){
if ($excerpt) return $excerpt;
$text = strip_shortcodes( $text );
$text = apply_filters(\'the_content\', $text);
$text = str_replace(\']]>\', \']]>\', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters(\'excerpt_length\', 55);
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . \'[...]\');
$words = preg_split("/[\\n
]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(\' \', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(\' \', $words);
}
return apply_filters(\'wp_trim_excerpt\', $text, $raw_excerpt);
}