og是一种新的HTTP头部标记,用了Meta Property=og标签,可以让网页成为一个“富媒体对象,就是你同意了网页内容可以被其他社会化网站引用等。目前谷歌、百度、360、bing等搜索引擎都加强了对og标签的重视。

什么是OG标签

OG全称是Open Graph Protocol,中文是开放内容协议,也称为OG标签。

它是 Facebook 在 2010 年 F8 开发者大会公布的一种网页元信息(Meta Information)标记协议,属于 Meta Tag (Meta 标签)的范畴,是一种为社交分享而生的 Meta 标签。

到目前几乎主流的社交媒体网站都支持 OG 协议。国内的百度、360 搜索、微博、微信、人人网等也支持该协议。

og标签的意义

以百度为例,百度星火计划原创规范v2.0就说明了og标签的使用。

百度og标签

og标签,即在页面添加这种协议可以让网页成为一个“富媒体对象”,表示同意网页内容可以被其他社会化网站引用等。

据说是对SEO有好处的。具体的效果就不清楚了。只能说应该没有什么坏处吧。

此外,我一个同学的hexo-butterfly主题,发现用的就是og标签。

butterfly主题默认是og标签

给页面添加og标签可以被搜索引擎发现并评估权重,加强meta信息优化内容;对于搜索引擎的权重提升和排名还是很有利的。

typecho的og标签

找了找,一共有这些og标签:

<meta property="og:site_name" content="<?php $this->options->title() ?>" />
<!-- 表明当前页面所在网站名称 -->
<meta property="og:type" content="article" />
<!-- 表明当前页面类型符合OG协议中的文章作品类型 -->
<meta property="og:url" content="<?php $this->permalink() ?>" />
<!-- 表明当前页面的url地址 -->
<meta property="og:title" content="<?php $this->title() ?>" />
<!-- 表明当前页面标题 -->
<meta property="og:description" content="<?php $this->description(); ?>" />
<!-- 表明当前页面的简单描述 -->
<meta property="og:image" content="<?php $this->fields->bimg(); ?>" />
<!-- 表明当前页面的缩略图 此处请根据自己的情况自己调整代用代码-->
<meta property="og:category" content="<?php $this->category(',', false); ?>" />
<!-- 表明当前页面所在的栏目 非星火计划支持,单独添加的-->
<meta property="article:author" content="<?php $this->author(); ?>" />
<!-- 表明当前页面的作者署名字段,需要在页面做展示-->
<meta property="article:publisher" content="<?php $this->options->siteUrl(); ?>" />
<!-- 表明当前页面的发布者 一般放网址-->
<meta property="article:published_time" content="<?php $this->date('c'); ?>" />
<!-- 表明当前页面最早发布时间,该字段必选,可以不在页面中做展示,内容格式要求符合ISO8601规范的UTC格式,标准格式应当是“YYYY-MM-DDTHH:MM:SS+时区” 此处请根据自己的情况自己调整代用代码-->
<meta property="article:published_first" content="<?php $this->options->title() ?>, <?php $this->permalink() ?>" />
<!-- 表明当前页面的原发媒体名称和链接,用于区分原创和转载,该字段为可选。原创时,链接与自身相同;转载时,链接是另外不同的地址-->
<meta property="article:tag" content="<?php $this->keywords(',');?>" />
<!-- 表明当前页面的TAG标签, 非星火计划支持,单独添加的-->

上面是比较齐全的,可以自己自己需求进行增删,也可以参考本站。

本站的og标签

themes/handsome/component/header.php中,在<head>标签里合适的位置添加代码:

只在文章页添加,is('post')进行判断:

    <?php if ($this->is('post')) : ?>
<!--内页seo优化-->
    <meta property="og:site_name" content="<?php $this->options->title() ?>" />
<!-- 表明当前页面所在网站名称 -->
    <meta property="og:type" content="article" />
<!-- 表明当前页面类型符合OG协议中的文章作品类型 -->
    <meta property="og:url" content="<?php $this->permalink() ?>" />
<!-- 表明当前页面的url地址 -->
    <meta property="og:title" content="<?php $this->title() ?>" />
<!-- 表明当前页面标题 -->
    <meta property="og:description" content="<?php $this->description(); ?>" />
<!-- 表明当前页面的缩略图 此处请根据自己的情况自己调整代用代码-->
    <meta property="og:category" content="<?php $this->category(',', false); ?>" />
<!-- 表明当前页面所在的栏目 非星火计划支持,单独添加的-->
    <meta property="article:author" content="<?php $this->author(); ?>" />
<!-- 表明当前页面的作者署名字段,需要在页面做展示-->
    <meta property="article:publisher" content="<?php $this->options->siteUrl(); ?>" />
<!-- 表明当前页面的发布者 一般放网址-->
    <meta property="article:published_time" content="<?php $this->date('c'); ?>" />
<!-- 表明当前页面最早发布时间,该字段必选,可以不在页面中做展示,内容格式要求符合ISO8601规范的UTC格式,标准格式应当是“YYYY-MM-DDTHH:MM:SS+时区” 此处请根据自己的情况自己调整代用代码-->
    <meta property="article:published_first" content="<?php $this->options->title() ?>, <?php $this->permalink() ?>" />
<!-- 表明当前页面的原发媒体名称和链接,用于区分原创和转载,该字段为可选。原创时,链接与自身相同;转载时,链接是另外不同的地址-->
    <meta property="article:tag" content="<?php $this->keywords(',');?>" />
<!-- 表明当前页面的TAG标签, 非星火计划支持,单独添加的-->
<?php endif; ?>  

添加的代码

本文标签: 网站开发

版权声明 ▶ 本网站名称:陶小桃Blog
▶ 本文链接:https://www.52txr.cn/2022/ogmeta.html
▶ 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行核实删除。
▶ 转载本站文章需要遵守:商业转载请联系站长,非商业转载请注明出处并附带原文链接!!
▶ 站长邮箱 [email protected][email protected] ,如不方便留言可邮件联系。

小陶的个人微信公众号

学累了就来张美女照片养养眼吧,身体是革命的本钱,要多多休息哦~ 随机美女图片

最后修改:2022 年 07 月 02 日
如果觉得我的文章对你有用,请随意赞赏!