search
Homephp教程php手册让wordpress评论分页更有利于SEO

让wordpress评论分页更有利于SEO

Jun 06, 2016 pm 08:08 PM
seowordpressPaginationarticleComment

本篇文章会让你们受益终生,建议你们认真看看. 这几天有看到关于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>

改成

<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>

效果如图

解决重复元说明的问题

如果你的主题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;
}

$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');

效果如图


DEMO地址:随便给一个吧,这里
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool