修复WordPress的Google丰富网页摘要错误

手册/FAQ (390) 2016-01-16 13:29:29

 最近在使用Google丰富网页摘要测试工具的时候,发现对于默认Wordpress博客,总会有三条错误信息出现,今天我就介绍一下,如何通过修改Wordpress模版文件来修复这些错误信息的方法。

 

错误信息内容分别是:

 

Warning: Missing required field "entry-title".

Warning: Missing required field "updated".

Warning: Missing required hCard "author".

 

修复Wordpress的Google丰富网页摘要错误

 

对于entry-title的错误信息修改方法是:

 

打开single.php文件,找到类似<h1><?php the_title(); ?></h1>一行,将其修改为<h1 class="title entry-title"><?php the_title(); ?></h1>(有些模版可能是h2或其他)

 

对于updated的错误信息修改方法是:

 

打开single.php文件,找到<?php the_date();?>一行,将其修改为<div class="date updated"><?php the_time('F S, Y'); ?></div>

 

对于author的错误信息修改方法是:

 

打开single.php文件,找到<?php the_author(); ?>一行,将其修改为<span class="vcard author"><span class="fn"><?php the_author(); ?></span></span>

 

另外,在昨天写的“Google丰富网页摘要教程”中,有些读者希望能举个Wordpress模版修改的例子,下面就是一个Wordpress模版的例子。

 

打开single.php文件,在适当位置添加如下代码:

 

<?php

$separator = '›';

$category = get_the_category();

if ($category) {

foreach($category as $category) {

echo '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb" style="display:inline">';

echo $separator . "<a href=\"".get_category_link($category->term_id)."\" itemprop=\"url\"><span itemprop=\"title\">$category->name</span></a>

";

echo '</div>';

}}

?>

THE END