/**
* Add a “Popular” label to posts with many comments
*/
function custom_add_popular_post_label( $title, $post_id ) {
if ( is_admin() || get_post_type( $post_id ) !== ‘post’ ) {
return $title;
}
$comment_count = get_comments_number( $post_id );
if ( $comment_count >= 10 ) {
$title .= ‘ <span class=”popular-post-label”>Popular</span>’;
}
return $title;
}
add_filter( ‘the_title’, ‘custom_add_popular_post_label’, 10, 2 );
Add the PHP code to your theme's functions.php file or a PHP snippets plugin.
Save and activate the snippet.
Posts with 10 or more comments will automatically display a Popular label.
Tested on
WordPress 6.8
Reported by the author on November 2, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.4. It may still work.
