There's nothing more annoying than pingbacks displaying in the WordPress Recent Comments Widget. This week I set out on a quest to discover how to remove them from the widget. I'd already discovered how to have them not display on the comments page, but the widget is different altogether and the fix is so simple that I could kick myself. The sourcecode for the recent comments widget can be found in the wp-includes/default-widgets.php file. Search for the line that says:
and change it to
That's all it takes to filter the pingbacks out. Of course, you really don't want to mess around with the default WordPress widgets. Any WordPress update will overwrite your changes. What I did was copy the default Recent Comments source code and added to the bottom of my theme's functions.php. The new code is below. It has been modified so it does not conflict with the default widget.
If I just wanted to override just the constructor function in functions.php, as opposed to the all of WP_Widget_Recent_Comments, leaving the rest in default-widgets.php to possibly be recoded by a WP update, would that be possible? And if so, how? Thanks.
I’m currently using an edit directly in default-widgets.php, understanding I’d need to add a new line after any update. But the other solution leaves the possibility of not incorporating potentially useful amendments.
Sorry — confusion. It’s not the constructor function I was referring to. It was the filtering code:
$comments = get_comments( apply_filters( ‘widget_comments_args’, array( … )
Being that that is not a function, but an assignment, I suspect that a successful means of bringing that alone into functions.php may be less likely. But still hoping…
Hi Rick,
You’re right that you shouldn’t modify default widgets. I don’t know of any way to change the assignments and leave default widgets intact. You may have to do what I did—create your own widget. If you copy the default widget and modify it as I mentioned in the article above, you’ll be able to achieve what you need to do.
Victor
Three years later your simple tweak still works like a charm. I can’t believe this issue hasn’t been fixed by WP, there are so many frustrated threads about it, but this was the only solution I found. Thank you.
Thanks Karl!
Thanks, found the pingback article useful, it’s working great!
Thanks, this worked great! I used it to remove the comment author link by changing get_comment_author_link to get_comment_author.
Mahalo Victor for sharing this method of removing the pingbacks. I have been trying for several months to figure this out and your tip worked like a charm.