天天看点

WordPress博客文章页如何添加OG协议标签

我们已经知道开放内容(OG)协议对SEO优化的作用,而在日常应用中,我们也能经常看到一些WordPress博客会在自己的页面的部分加入OG协议,实现起来很容易。

今天就说说如何为WordPress博客文章页添加OG协议标签。因为WordPress大部分为文章形式页面,所以我们只需要添加以下几个协议即可:

og:type //页面内容类型,wordpress博客通常使用article文章类型即可。 og:title //这里是文章标题 og:description //页面的简单描述,wordpress中可以使用文章摘要 og:site_name //页面所在网站名,wordpress中使用博客网站名称 og:url //文章页面url地址 og:image //文章略缩图地址

添加方式为,找到当前主题使用header.php文件,在标签内部插入代码:

<meta property="og:type" content="acticle"> <meta property="og:title" content="<?php wp_title('-', true, 'right'); echo get_option('blogname'); if (is_home ()) echo get_option('blogdescription'); if ($paged > 1) echo '-Page ', $paged; ?>"> <meta property="og:site_name " content="<?=get_bloginfo('name');?>"> <meta property="og:description" content="<?php the_excerpt();?>"> <meta property="og:url" content="<?php the_permalink();?>"/> <meta property="og:image" content="<?php wpjam_post_thumbnail();?>">