WordPress widget latest comments display comment content

WordPress widget latest comments display comment content

The default sidebar of wordpress has a latest comments widget, which does not display the comment content by default. The following modification can display the comment author and comment content.
Modify the file: wp-includes/default-widgets.php
turn up:

 if ( $comments ) { // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); foreach ( (array) $comments as $comment) { $output .= '<li>' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; } }

to:

if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= '<li class="recentcomments">' . /* translators: comments widget:
1: comment author, 2: post link */ sprintf(_x('%1$s : %2$s', 'widgets'),
get_comment_author_link(), '<a href=”' . esc_url( get_comment_link($comment->comment_ID) ) . '”>' . mb_strimwidth(strip_tags($comment->comment_content),0,46,”,'utf-8′) . '</a>') . '</li>';
}
}

The display effect is as follows:

<<:  Ajenti: Excellent Web Management Panel for Linux

>>:  Free VPS: vps.me successful application and shared IP usage tutorial

Recommend

HostMyBytes: $5/year/128MB RAM/10GB storage/1TB bandwidth/OpenVZ/Los Angeles

HostMyBytes is a Canadian hosting company founded...

Two .com domains for $4.99 for the first year

1. https://www.DomainRightNow.com/ First year $4....

WordPress theme: Yarlan Chinese version, enhanced and optimized version

Yarlan is a Russian WordPress theme. I don’t unde...

adf.ly: Making money with URL shorteners

Adf.ly now supports Chinese. Adf.ly's profile...

VPS.DO: $5/month/1GB RAM/25GB NVMe space/1TB bandwidth/1Gbps port/XEN/Ogden

VPS.DO is probably a new business, mainly providi...

DGCHost: $2.1/month/512MB memory/20GB SSD space/1TB traffic/KVM/Hong Kong

DGCHost is a Singapore hosting provider under Dig...

ServerStatus-Hotaru: Create your own server monitoring

Based on Linux. At least 2 machines are required,...