[wp-trac] [WordPress Trac] #63843: `<wfw:commentRss>` in feeds can be empty causing invalid feed when filtered by `post_comments_feed_link`

WordPress Trac noreply at wordpress.org
Tue Aug 19 21:54:37 UTC 2025


#63843: `<wfw:commentRss>` in feeds can be empty causing invalid feed when filtered
by `post_comments_feed_link`
--------------------------+------------------------------
 Reporter:  jerclarke     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Feeds         |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  2nd-opinion   |     Focuses:
--------------------------+------------------------------

Comment (by jerclarke):

 I'll add that in writing up this ticket, which I think remains a valid
 bug, I did come up with a solution to stop the per-post feed URLs showing
 in RSS without errors.

 The combination of these three filters seems to do the trick (though I
 haven't tested it heavily yet):

 {{{
 function gv_disable_insert_post_comments_feed($for_comments) {

         return '';
 }
 add_filter('post_comments_feed_link',
 'gv_disable_insert_post_comments_feed');


 function gv_disable_post_comment_feeds_filter_get_comments_number(int
 $comments_number, int $post_id) {

     if (!is_feed()) {
         return $comments_number;
     }

     return 0;
 }
 add_filter('get_comments_number',
 'gv_disable_post_comment_feeds_filter_get_comments_number', 10, 2);

 function gv_disable_post_comment_feeds_filter_comments_open( bool
 $comments_open, int $post_id ) {

     if (!is_feed()) {
         return $comments_open;
     }

     return false;
 }
 add_filter('comments_open',
 'gv_disable_post_comment_feeds_filter_get_comments_number', 10, 2);
 }}}

 By "disabling comments" and pretending every post has zero comments when
 loading feeds, we get the effect that the specific current logic of `feed-
 rss2.php` is hijacked and the `<wfw:commentRss>` tag isn't output.

 The problem with this solution is obvious: It's indirect and could lead to
 all kinds of unpredictable side-effects. If `feed-rss2.php` is changed in
 the future, the URLs could end up being inserted again, and who knows what
 kind of knock-on effects it could have to "disable comments" on posts in
 this context.

 On top of that, this solution also removes the option of inserting the
 comment count without the feed. To me the `<slash:comments>` tag is mostly
 useless, but also totally harmless, there's no reason to have to throw
 this baby out with the bath water.

 I'll be using this solution for now, but it would be **so much more
 logical** for the template to honor just the first filter,
 `post_comments_feed_link`, and only insert the `<wfw:commentRss>` tag if
 there's a URL!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63843#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list