百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【站长工具】WordPress SEO优化:去除作者存档链接和日期链接(Twenty Ten主题为例)

发布时间:2020-09-17

作品分类:站长工具  链接  作者  代码  链接  为例  去除  优化  存档

IT131为新建的Windows 10 Pro(Win10专业网)依然启用了简洁明快的WordPress自带主题Twenty Ten,但是该主题在SEO方面没有进行优化,就说最简单的文章标题下面的“作者”和“发布日期”吧,作者都有一个指向作者存档的链接,发布日期则有一个指向文章地址的链接。

如图1:

2014-10-12_112818

而网站只有IT131一个作者,所以作者存档页面的内容与主页的完全一样,这对于SEO来说就是一种不利的重复信息。而发布日期带有文章地址的链接,也纯粹是多此一举,除了增加搜索引擎蜘蛛的负担,并无任何作用。所以我们最好去掉作者存档的链接和发布日期的链接。

IT131先在网上搜索,但是只有为作者存档链接添加nofollow的例子,需要编辑\wp-includes\author-template.php其中的代码:

1
 <a href="%1$s" title="%2$s" rel="author">%3$s</a>

IT131想那现在要删除链接,直接去掉链接代码不就行了吗?可是删除了author-template.php中所有的链接代码都没有作用。 于是IT131觉得Twenty Ten主题控制作者存档链接和日期链接的代码应该不是在author-template.php,而是在主题文件夹里,经过一番查找终于在主题的functions.php里找到了相关代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()
           )
       );
}

里面有两个链接代码,第一个是日期指向文章地址的链接,第二个是作者指向作者存档的链接。把这两个链接代码去除之后,以上代码变成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function twentyten_posted_on() {
    printf( __( 'Posted on %2$s by %3$s', 'twentyten' ),
        'meta-prep meta-prep-author',
        sprintf( '%3$s',
            get_permalink(),
            esc_attr( get_the_time() ),
            get_the_date()
            ),
        sprintf( '%3$s',
            get_author_posts_url( get_the_author_meta( 'ID' ) ),
            esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
            get_the_author()
            )
        );
}

这样就可以去除作者存档和日期的链接了。效果如图2:

2014-10-12_113355

PS:另外,你还可以选择不去除链接,而是在参照倡萌分享的《将WordPress的作者存档链接重定向到about页面》修改一下指向链接;或者是为链接添加nofollow属性也可以,添加方法是在上面的代码中添加rel=”nofollow”即可。

Top