Home > php教程 > php手册 > body text

让wordpress评论分页更有利于SEO

WBOY
Release: 2016-06-06 20:08:47
Original
1316 people have browsed it

本篇文章会让你们受益终生,建议你们认真看看. 这几天有看到关于wordpress评论分页不利于SEO的文章,网上也有一些不建议开启评论分页的,总结一下就是这么几点: 评论分页导致——不同链接下重复标题(title),重复的元说明(description)以及文章内容相同. 不开启

本篇文章会让你们受益终生,建议你们认真看看.
这几天有看到关于wordpress评论分页不利于SEO的文章,网上也有一些不建议开启评论分页的,总结一下就是这么几点: 评论分页导致——不同链接下重复标题(title),重复的元说明(description)以及文章内容相同.
不开启评论分页会要了我的命,你们知道我评论有多长,so,分页还是要开滴,SEO也是要兼顾滴,鱼和熊掌是可以兼得滴!

解决重复标题的问题

在你主题的header.php内找到类似代码:

<title>
<?php global $page, $paged;
wp_title( '|', true, 'right' );
bloginfo( 'name' );
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( '第%s页', 'xiaohudie' ), max( $paged, $page ) );
?>
</title>
Copy after login

改成

<title>
<?php global $page, $paged;
	wp_title( '|', true, 'right' );
	bloginfo( 'name' );
	if ( $paged >= 2 || $page >= 2 )
		echo ' | ' . sprintf( __( '第%s页', 'xiaohudie' ), max( $paged, $page ) );
	if ( ! empty( $cpage ) )//如果有评论页数且不是第一页
		echo ' | ' . sprintf( __( '评论第%s页', 'xiaohudie' ), $cpage );?>
</title>
Copy after login

效果如图

解决重复元说明的问题

如果你的主题header标签内有description功能,可以在最后加上如下代码

if ( $paged >= 2 || $page >= 2 ){
	$description .= ':第'.max( $paged, $page ).'页';
}
if ( ! empty( $cpage ) ){
	$description = sprintf('《%1$s》评论的第%2$s页:', get_the_title(),$cpage).$description;
}
Copy after login

$description需要根据之前的代码来修改,如果你主题没有这个功能,就先自己上网找找相关教程吧.此事就不在本文讨论范畴了.
此段代码顺便把首页分页标题重复的问题也解决了,效果如图

解决文章内容相同的问题

实现此功能有个插件:Paged Comments SEO,也可以直接把以下代码扔到functions.php

function xiaohudie_seo_paged_comments($new_content = '') {
if ( ! empty( $cpage ) ) {
	remove_filter('the_content', 'xiaohudie_seo_paged_comments');//去除原文内容
	$new_content = sprintf('您现在正在《%1$s》评论的第%2$s页', get_the_title(),$cpage);
	$new_content .= '<blockquote>'. mb_strimwidth(get_the_content(),0,200).'</blockquote>' ;
	//$new_content .= '<blockquote>'. get_the_excerpt().'</blockquote>' ;//如果你的主题带截断摘要,或者你的文章都有摘要,可以把上一行换成此行
} 
return $new_content;
}
add_filter('the_content', 'xiaohudie_seo_paged_comments');
Copy after login

效果如图


DEMO地址:随便给一个吧,这里
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!