网站添加头部Meta property=og协议的使用方法详解教程

Meta Property=og怎么使用?wordpress如何调用og:type?怎么在文章中调用og:title?如何使用wp调取文章og:image?本文将介绍什么是Meta Property=og协议以及该协议的用法!

什么是Meta Property=og协议?

og是一种新的HTTP头部标记(Open Graph协议)这种协议可以让网页成为一个“富媒体对象”(被其他网站引用等)。目前主流百度,360等等搜索引擎已经支持og富媒体协议!

Meta Property=og协议的作用?

1、能够正确被蜘蛛抓取您的内容到百度、360、搜狗等网页搜索;

2、帮助您的内容更有效的在百度、360、搜狗结构化展现;

3、能够正确的分享您的内容到SNS网站;

4、帮助您的内容更有效的在SNS网络中传播;

Meta Property=og标签的应用

在<head>和</head>中添加入meta标签,并填上相应的内容

如果一个页面上有多个需要标识出的内容怎么办?

您可以重复meta标签,将认为og:type 标签是每一段内容的起始处,以随心网为例:

<meta property="og:type" content="article" />
<meta property="og:title" content="网站添加头部Meta property=og协议的使用方法详解教程" />
<meta property="og:author" content="随心网" />
<meta property="og:image" content="http://www.sxlog.com/logo.jpg" />
<meta property="og:site_name" content="随心网" /> 
<meta property="og:description" content="Meta Property=og怎么使用?wordpress如何调用og:type?怎么在文章中调用og:title?" />
<meta property="og:url" content="http://www.sxlog.com/AA.html" />
<meta property="og:release_date" content="2018年5月26日 12:37" />

<meta property="og:type" content="article" />

<meta property="og:title" content="网站添加头部Meta property=og协议的使用方法详解教程"/>

<meta property="og:author" content="随心网" />

<meta property="og:image" content="http://www.sxlog.com/logo.jpg" />

<meta property="og:site_name" content="随心网" />

<meta property="og:description" content="Meta Property=og怎么使用?wordpress如何调用og:type?怎么在文章中调用og:title?" />

<meta property="og:url" content="http://www.sxlog.com/AA.html" />

<meta property="og:release_date" content="2018年5月26日 12:37" />

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 音频地址

WordPress添加头部Meta property=og协议

要在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 } ?>

原文地址:

https://www.sxyye.com/archives/505.html

本博客所有文章如无特别注明均为原创。作者:随心复制或转载请以超链接形式注明转自随心网
原文地址《网站添加头部Meta property=og协议的使用方法详解教程

相关推荐

网友评论(0)