下面是最近一个项目的代码示例。这将设置特定帖子的OpenGraph属性。将代码添加到标题。
<?php if (is_single()) { // Display only on single posts ?>
<?php $thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID));
// Optionally, use the code below (untested) to get a thumbnail based on a specific thumbnail size
// $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), \'custom-thumbnail-name\');
?>
<meta property="og:title" content="<?php echo get_the_title($post->ID); ?>" />
<meta property="og:url" content="<?php echo get_permalink($post->ID); ?>" />
<meta property="og:image" content="<?php echo $thumbnail_url[0]; ?>" />
<meta property="og:site_name" content="Website Name" />
<meta property="og:type" content="article" />
<meta property="fb:admins" content="732866210" />
<?php } ?>