首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google snippet测试中的hatom-entry错误

Google snippet测试中的hatom-entry错误
EN

Stack Overflow用户
提问于 2013-10-11 18:37:58
回答 1查看 855关注 0票数 1

我几乎可以肯定我不是第一个有这个问题的人,但是当我在Google Snippet test Tool上测试我的(WordPress) page时,我得到了很多错误,比如:

代码语言:javascript
复制
hatom-feed

hatom-entry:
    
Fout: At least one field must be set for HatomEntry.

Fout: Missing required field "entry-title".

Fout: Missing required field "updated".

Fout: Missing required hCard "author".

我找到了一些关于这方面的tutorials,但那是针对标准WordPress主题的。我使用的是来自ThemeForest的Inovado,但我不知道必须在哪个文件中编辑此数据。

熟悉这个的人吗?

我在代码片段审查方面也遇到了问题...测试结果很好,但不会出现在de Google搜索结果中。不知道为什么..。

EN

回答 1

Stack Overflow用户

发布于 2014-08-22 15:53:03

您可以将此代码添加到主题目录中的function.php文件中,它将解决这些问题。

代码语言:javascript
复制
//mod content
function hatom_mod_post_content ($content) {
if ( in_the_loop() && !is_page() ) {
$content = '<span class="entry-content">'.$content.'</span>';
 }
 return $content;
}
add_filter( 'the_content', 'hatom_mod_post_content');

//add hatom data
function add_mod_hatom_data($content) {
$t = get_the_modified_time('F jS, Y');
$author = get_the_author();
$title = get_the_title();
if(is_single()) {
    $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was    last modified: <span class="updated"> '.$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
}
return $content;
}
add_filter('the_content', 'add_mod_hatom_data');

代码包含2个函数。第一个函数将使用“the_content”的WordPress过滤器钩子将“entry-content”类添加到文章中。为了添加其他基本的hAtom字段,第二个函数将在文章末尾添加一小句话,其中包含更新时间、帖子标题和作者,以及所需的微数据。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19316102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档