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

人生从来没有真正的绝境。无论遭受多少艰辛,无论经历多少苦难,只要一个人的心中还怀着一粒信念的种子,那么总有一天,他就能走出困境,让生命重新开花结果。

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

如图1:

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

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

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

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

三好公民想那现在要删除链接,直接去掉链接代码不就行了吗?可是删除了author-template.php中所有的链接代码都没有作用。 于是三好公民觉得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 rel="nofollow noopener noreferrer" 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" rel="nofollow noopener noreferrer" 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()
           )
       );
}

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 rel="nofollow noopener noreferrer" 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" rel="nofollow noopener noreferrer" 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()
            )
        );
}

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:

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

本文WordPress SEO优化:去除作者存档链接和日期链接(Twenty Ten主题为例)到此结束。生气是拿别人做错的事来惩罚自我。小编再次感谢大家对我们的支持!

标签: 为例 SEO