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

如果想向上图一样,恢复评论内容的格式,将下面的代码添加到当前主题的 functions.php 即可:
/**
* 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');
来源:
https://www.wpdaxue.com/full-comments-on-dashboard.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32436.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57