以上 2 years ago I published an article on how to fix problems with WordPress themes which didn’t pass the Google Rich Snippets Testing Tool. 从那时起,很多已经改变 - WordPress和大多数主题有更好的支持, HTML5和CSS3已经抵达, 和谷歌, 雅虎和Bing聚在一起,决定将重点放在微观数据, 通过schema.org. 当时似乎微格式来标记网页的最简单方法, 和测试工具必须为这些最全面的支持. 此举对微观数据的变化和对WordPress的需要新文章: 这是它!
而不是有很多不同的主题不同的文章,我决定尝试提供的所有信息 1 指导. 这使得它更容易跟上, 并表示有刚 1 中心点为所有请求和讨论. 这也使得更多的意义,因为几个步骤都是一样的,不管你用的是什么主题. 我不打算在本文中介绍的所有选装, 只是基础知识,让您的网站,以验证与工具. 一旦你管理,你应该找到添加额外的标记相对容易. 所以,让我们开始...
从谷歌的个人资料将链接添加到您的网站
你会看到 我的Google 亲文件 我有一间酒吧,里克链接 https://diymediahome.org - 你将需要相同的为自己的网站. 理想情况下,您将需要所有作者有被以同样的方式,因为这链接到您的网站谷歌个人资料.
- 登录到您的 谷歌亲文件
- 向下滚动,直到看到 链接 部某处朝向页面底部右侧
- 点击 编辑 链接
- 根据 贡献者 仲tion点击 添加自定义的链接
- 确保选中的文本的权利 贡献者 被设置为 公
- 输入您的网站名称 (e.g. DIY 媒体主页) 和地址 (e.g. https://diymediahome.org)
- 点击保存
添加从您的网站链接到您的谷歌个人资料
现在,我们需要添加从你的作者页面链接到您的谷歌个人资料. 有 2 ALTERN - 在 - 香港专业教育学院的方式来做到这一点, 我高度使用Yoast推荐修补 本 插件.
- 安装 Yoast 本 plugin 或 下面的代码添加到你的主题的functions.php文件123456789function update_contactmethods( $contactmethods ) {// Add Google Profiles$contactmethods[‘googleplus’] = ‘Google+’;// Add Twitter$contactmethods[‘twitter’] = __( ‘Twitter username (without @)’, ‘wordpress-seo’ );return $contactmethods;}add_filter( ‘user_contactmethods’, ‘update_contactmethods’, 10, 1);
- 转到您的个人资料笔者在WordPress后台管理界面 (笼罩 用户 在左侧菜单, 并点击 您的Pro文件)
- 在 Google+的 字段添加一个链接到您的谷歌亲文件 (e.g. https://plus.google.com/104657888470728381512 /)
- 确保任你, 或您的其他网站的作者做同样的事情, 每个链接到您自己的谷歌配置文件
- 现在, 如果您使用的是Yoast PLU-杜松子酒, 进入 本 菜单并选择 标题和METAS, Ç舔上 家 在页面的顶部,并在菜单中 作家高光ING 下拉框中选择要用作主页的作者使用的用户
- 如果你坚持对不使用Yoast插件,你需要手动添加以下代码到header.php文件 (想当然地使你有一个). 不要忘了我的谷歌个人资料网址更改为你的。此代码将使用后作者的谷歌个人资料网址,如果有一个有效的, 并且将使用默认 (你的) 如果不存在.1<link rel=“author” href=”<?php $gplus = ‘https://plus.google.com/115369062315673853712/posts’; if ( is_singular() ) {global $post; $gplus = get_the_author_meta( ‘googleplus’, $post->post_author );} echo $gplus; ?>”/>
修正了一个失踪“更新”字段的错误
大多数WordPress主题包括有关当后发表在后信息区信息, 但是当它最后一次更新也很少有. 这是一个遗憾, 因为更新是必需的,而实际公布的是不! 加入很容易,虽然, 并再次, 有 2 途径, 正确的方式快速破解方法. 我建议当然是正确的方法, 但如果需要的话可以诉诸快速破解. 我们也将在微改变微观数据在同一时间.
有道
我们要添加一些额外的信息发布标题, 无论是搜索引擎和我们的观众. 我们需要做上岗, 网页, 档案和主页.
- 我们需要找到一个包含它生成发布链接的代码文件. 这几乎肯定会使用WordPress的功能 get_the_date(). 您可以通过您的主题文件搜索, 或指主题具体细节下面,我已经提供了详细信息大量主题
- 我们将检查发布和更新日期是相同的. 如果他们是我们将只需要添加额外的 dateUp过时 itemprop但如果它们是不同的,我们会输出一些额外的文本访问者
- 我们要添加的fol-低ING (并修改它,因为它解释)1234567891011121314151617<?php if(get_the_date()==get_the_modified_date()): ?>//we’re going to use the original code just with the updated class added//put your theme’s original code here//remove any class=””//add itemprop=“datePublished dateCreated dateModified” to the HTML tag surrounding the get_the_date() function<?php else: ?>//we’re going to use slightly code just with the updated date added//copy your theme’s original code to here and then modify it as below//remove any class=””//add itemprop=“datePublished dateCreated” to the HTML tag surrounding the get_the_date() function//add in a new html tag into the line where you want it to appear as below//Updated <?php echo get_the_modified_date() ?><?php endif; ?>
- 你要么必须弄清楚原来的主题的代码和编辑, 或请参阅下文的具体议题的细节.
- 您可能需要重复此编辑多个文件
快速破解
我们要欺骗并提供发表日期作为更新日期, 即使后实际上已更新最近. 如果帖子被更新,那么我们就实际上是提供的信息不正确, 但它仍然会验证. 这真的是更好地正确,如果有可能做到这一点, 但如果你坚持做这种方式阅读. 正如上面我们需要做这个职位, 网页, 档案和主页.
- 如上述,我们需要找到包含产生所公布链路的代码的文件. 这几乎肯定会使用WordPress的功能 get_the_date(). 您可以通过您的主题文件搜索, 或者参考下面的表格,我已经提供了详细信息大量的主题
- 找到 HTML 元件围绕的日期 (常常将有
class="published"
). - 通过除去类并加入以下代替编辑元件
itemprop="datePublished dateCreated dateUpdated"
- 正如上文, 您可能需要重复此编辑多个文件
更换内置微 (由于混合式摘要格式打破东西)
默认情况下,WordPress是仍然使用微格式标记征求意见, 这可悲的是,似乎打破东西像食谱微观数据的标记. 解决这个问题的最好办法是删除微格式标记,并用微数据标记取代. 遗憾的TU-nately, 产生这种标记的WordPress的核心功能没有便利过滤器或钩所以这需要一点摆弄一下.
在评论部分更换电子名片
- 我们现在要做的是使用注释回调改变评论输出. 许多主题已经在使用回调,我们可以修改, 而对于那些基于WordPress的默认不,我们将添加一个
- 检查你的主题已经有评论回调 - 搜索你的主题文件功能
wp_list_comments
. 如果它包括代码callback=
要么'callback' =>
然后将其用回调,你应该能够找到 (大概的functions.php) 通过寻找回调函数的名称, 这是继等号(=)或箭头部分, e.g.wp_list_comments( array( 'callback' => 'twentyten_comment' ) );
要么wp_list_comments('type=comment&callback=bones_comments');
. If it doesn’t then we will need to add one by addingcallback=diymh_comment
要么array( 'callback' => 'diymh_comment' )
到行. - 如果您需要添加注释的回调,那么你将需要添加以下代码的functions.php123456789101112131415161718192021222324function diymh_comment($comment, $args, $depth) {$GLOBALS[‘comment’] = $comment; ?><li <?php comment_class(); ?> id=“li-comment-<?php comment_ID() ?>”><div id=“comment-<?php comment_ID(); ?>”><div class=“comment-author novcard”><?php echo get_avatar($comment,$size=‘48’,$default=’<path_to_url>’ ); ?><?php printf(__(‘<cite class=“fn”>%s</cite> <span class=“says”>says:</span>’), get_comment_author_link()) ?></div><?php if ($comment->comment_approved == ‘0’) : ?><em><?php _e(‘Your comment is awaiting moderation.’) ?></em><br /><?php endif; ?><div class=“comment-meta commentmetadata”><a href=”<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>”><?php printf(__(‘%1$s at %2$s’), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__(‘(Edit)’),’ ‘,”) ?></div><?php comment_text() ?><div class=“reply”><?php comment_reply_link(array_merge( $args, array(‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’]))) ?></div></div><?php}
- 你会发现,这段代码有
class="novcard"
代替原有的class="vcard".
- 如果你的主题确实有它自己的回调,你需要找到的回调函数和替换的任何实例
class="vcard"
同class="novcard"
在头替换hfeed
- 下一个, 我们还需要删除的任何实例
class="hfeed"
, 这是通常的header.php发现. 更换所有出现hfeed
同nohfeed
更换hentry和标题丰富网页摘要
- 我们完全可以替代这些元素有几个整齐的功能添加到的functions.php12345678910function diymh_replace_hentry($classes){if(($key = array_search(‘hentry’, $classes)) !== false) $classes[$key]=‘nohentry’;return $classes;}add_filter(‘post_class’,‘diymh_replace_hentry’);function diymh_microdata_title($title) {return ‘<span itemprop=“name”>’.$title.’</span>’;}add_filter(‘the_title’, ‘diymh_microdata_title’, 10, 2);
添加信息的类型 (e.g. 文章, 食谱, 等等) 文章标题
- 第一, 决定要发布什么样的工作 - 最有可能的文章。看一看的列表中 schema.org
- 找到 HTML 标签,它包含了功能
post_class()
- 添加代码
itemscope itemtype="https://schema.org/Article"
(替代品,如果你选择了一个不同类型的工作)
最后, 以避免破坏任何样式
- 你将需要编辑你的主题的style.css并做了查找/替换操作替换的所有实例
.vcard
同.novcard
和替换的所有实例.hfeed
同.nohfeed
使我们的改变不会搞砸任何 CSS 我们的意见造型
修复任何其他错误
必要的其他任何更改将在下面每个主题的基础上详细介绍. 如果你有一个主题,你是无法修复,请发表评论. 如果它是一个免费的主题,请让我知道的主题名称, and if it is a premium theme please let me know so I can provide you with an e‑mail address to send a zipped copy to.
主题具体细节
只是在进行之前这些编辑不要忘记进行到您的谷歌个人资料和你的网站相互链接的步骤, 并安装Yoast 本, 或者添加上面的代码提供.
二十年 1.5
在functions.php文件替换此
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | function twentyten_posted_on() { printf( __( ‘<span class=”%1$s”>Posted on</span> %2$s <span class=“meta-sep”>by</span> %3$s’, ‘twentyten’ ), ‘meta-prep meta-prep-author’, sprintf( ‘<a href=”%1$s” title=”%2$s” rel=“bookmark”><span class=“entry-date”>%3$s</span></a>’, get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( ‘<span class=“author vcard”><a class=“url fn n” href=”%1$s” title=”%2$s”>%3$s</a></span>’, get_author_posts_url( get_the_author_meta( ‘ID’ ) ), esc_attr( sprintf( __( ‘View all posts by %s’, ‘twentyten’ ), get_the_author() ) ), get_the_author() ) ); } |
与此
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | function twentyten_posted_on() { if(get_the_date()==get_the_modified_date()){ printf( __( ‘<span class=”%1$s”>Posted on</span> %2$s <span class=“meta-sep”>by</span> %3$s’, ‘twentyten’ ), ‘meta-prep meta-prep-author’, sprintf( ‘<a href=”%1$s” title=”%2$s” rel=“bookmark”><span itemprop=“datePublished dateCreated dateModified”>%3$s</span></a>’, get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( ‘<span class=“author vcard”><a itemprop=“author” href=”%1$s” title=”%2$s”>%3$s</a></span>’, get_author_posts_url( get_the_author_meta( ‘ID’ ) ), esc_attr( sprintf( __( ‘View all posts by %s’, ‘twentyten’ ), get_the_author() ) ), get_the_author() ) ); } else{ printf( __( ‘<span class=”%1$s”>Posted on</span> %2$s <span class=“meta-sep”>by</span> %3$s. Updated <span itemprop=“dateModified”>%4$s</span>.’, ‘twentyten’ ), ‘meta-prep meta-prep-author’, sprintf( ‘<a href=”%1$s” title=”%2$s” rel=“bookmark”><span itemprop=“datePublished dateCreated”>%3$s</span></a>’, get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( ‘<span class=“author vcard”><a itemprop=“author” href=”%1$s” title=”%2$s”>%3$s</a></span>’, get_author_posts_url( get_the_author_meta( ‘ID’ ) ), esc_attr( sprintf( __( ‘View all posts by %s’, ‘twentyten’ ), get_the_author() ) ), get_the_author() ), get_the_modified_date() ); } } |
在functions.php文件替换此
336 | <div class=“comment-author vcard”> |
与此
336 | <div class=“comment-author novcard”> |
在header.php文件替换此
56 | <div id=“wrapper” class=“hfeed”> |
与此
56 | <div id=“wrapper” class=“nohfeed”> |
在loop.php (3 实例), 环的single.php, 环page.php和环路attachment.php替换此
1 | <div id=“post-<?php the_ID(); ?>” <?php post_class(); ?> |
与此
1 | <div id=“post-<?php the_ID(); ?>” <?php post_class(); ?> itemscope itemtype=“http://schema.org/Article”> |
二十十一 1.5
很快会来到...
Annotum基地 1.1.1
在 7 档 (功能特性,articles.php, 摘录类型article.php, 摘录摘录,default.php, 内容类型article.php, 内容 page.php, 内容内容default.php, 内容文章,pdf.php) 更换
1 | <article <?php post_class(‘article-full’); ?> |
同
1 | <article <?php post_class(‘article-full’); ?> itemscope itemtype=“http://schema.org/Article”> |
请通过下面的评论给我们你的想法! 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.
Thanks — working on it — eisenberg.co.za
伟大, grazie mille!