要在wordpress中插入og协议,找到主题header.php文件,在<head>和</head>中添加入meta标签,并填上相应的内容
<?php if (is_single()) { ?>
<meta property="og:type" content="acticle" />
<meta property="og:title" content="<?php the_title();?>" />
<meta property="og:author" content="<?php the_author();?>" />
<meta property="og:image" content="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" />
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:description" content="<?php $body=mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 200,); echo str_replace(array("\r\n","\r","\n"," ")," ",$body);?>" />
<meta property="og:url" content="<?php the_permalink() ?>" />
<meta property="og:release_date" content="<?php the_time('Y年m月d日 h:i');?>" />
<?php } ?>
因为og标签主页无效,所以增加一个PHP判断,仅在内容页生效
Meta Property=og主要标签属性
og:title 标题
og:type 类型(常用值:article book movie)
og:image 略缩图地址
og:author 作者名称
og:url 页面地址
og:release_date 发布时间
og:description 页面的简单描述
og:site_name 页面所在网站名
og:videosrc 视频或者Flash地址
og:audiosrc 音频地址