最近在使用 Google 豐富網頁摘要測試工具的時候,發現對於預設 WordPress 部落格,總會有三條錯誤資訊出現,今天我就介紹一下,如何透過修改 WordPress 模版檔案來修復這些錯誤資訊的方法。
錯誤資訊內容分別是:
Warning: Missing required field 「entry-title」 。
Warning: Missing required field 「updated」 。
Warning: Missing required hCard 「author」 。

對於 entry-title 的錯誤資訊修改方法是:
開啟 single.php 檔案,找到類似<h1><?php the_title();
?></h1> 一行,將其修改為<h1 ><?php
the_title(); ?></h1>(有些模版可能是 h2 或其他)
對於 updated 的錯誤資訊修改方法是:
開啟 single.php 檔案,找到<?php the_date();?> 一行,將其修改為<div ><?php the_time('F S, Y'); ?></div>
對於 author 的錯誤資訊修改方法是:
開啟 single.php 檔案,找到<?php the_author(); ?> 一行,將其修改為<span
><span ><?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>';
}}
?>