任何问题请联系WX:uu16853

买模板送网站采集器 让你轻松放开双手运营网站!

购买更多有优惠!

WordPress 仪表盘“近期评论”显示完整评论内容和格式

WordPress 仪表盘页面有一个“近期评论”小工具,用来显示网站最新的评论。但是默认情况下,会过滤掉评论的内容格式,比如换行分段,然后统统地显示为一段。有些时候,失去格式的内容阅读起来还挺不方便。

full-comments-on-dashboard-wpdaxue_com

如果想向上图一样,恢复评论内容的格式,将下面的代码添加到当前主题的 functions.php 即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * WordPress 仪表盘“近期评论”显示完整评论内容和格式
 * https://www.wpdaxue.com/full-comments-on-dashboard.html
 */
function full_comments_on_dashboard($excerpt) {
	global $comment;
 
	if ( !is_admin() )
		return $excerpt;
 
	$content = wpautop($comment->comment_content);
	$content = substr($content, 3, -5);	// 移除第一个 <p> 和最后一个 </p>
	$content = str_replace('<p>', '<p style="display:block; margin:1em 0">', $content);
 
	return $content;
}
add_filter('comment_excerpt', 'full_comments_on_dashboard');

/**
* WordPress 仪表盘“近期评论”显示完整评论内容和格式
* https://www.wpdaxue.com/full-comments-on-dashboard.html
*/
function full_comments_on_dashboard($excerpt) {
global $comment; if ( !is_admin() )
return $excerpt; $content = wpautop($comment->comment_content);
$content = substr($content, 3, -5); // 移除第一个 <p> 和最后一个 </p>
$content = str_replace(‘<p>’, ‘<p style="display:block; margin:1em 0">’, $content); return $content;
}
add_filter(‘comment_excerpt’, ‘full_comments_on_dashboard’);

100% Secure Checkout

PayPal / MasterCard / Visa