hooks - Remove lines from RSS Feed

admin2025-06-02  2

I'm trying to remove the "The post xxx appeared first on xxx" line in my RSS feed using the the_content_feed hook. I've tested the regex function outside wordpress on the feed and it works.

I'm using the my custom functions plugin to insert this into functions.php.

It does not seem to be working and I'm at a loss. Any ideas?

add_action('the_content_feed', 'remove_rss_links');
    function remove_rss_links($content) {
    return preg_replace(".*appeared first on.*$", "", $content);
}

Here is part of my feed (slightly redacted):

</p>
<p>The post <a rel="nofollow" href="/">Tees</a> appeared first on <a rel="nofollow" href="">Golf Course Renovation</a>.</p>
]]></description>

I'm trying to remove the "The post xxx appeared first on xxx" line in my RSS feed using the the_content_feed hook. I've tested the regex function outside wordpress on the feed and it works.

I'm using the my custom functions plugin to insert this into functions.php.

It does not seem to be working and I'm at a loss. Any ideas?

add_action('the_content_feed', 'remove_rss_links');
    function remove_rss_links($content) {
    return preg_replace(".*appeared first on.*$", "", $content);
}

Here is part of my feed (slightly redacted):

</p>
<p>The post <a rel="nofollow" href="http://foobar/tees/">Tees</a> appeared first on <a rel="nofollow" href="http://foobar">Golf Course Renovation</a>.</p>
]]></description>
Share Improve this question edited Mar 10, 2019 at 19:29 user302477 asked Mar 10, 2019 at 17:23 user302477user302477 133 bronze badges 5
  • Have you tried at a different priority - the third parameter for add_action(). – Nathan Johnson Commented Mar 10, 2019 at 17:53
  • You mean make it execute earlier? The default is as late as possible (10) – user302477 Commented Mar 10, 2019 at 19:28
  • Why is 10 as late as possible? – Nathan Johnson Commented Mar 10, 2019 at 20:04
  • @user302477 There's no hard limit, 10 is the default, you can go lower or much higher. – Jacob Peattie Commented Mar 11, 2019 at 13:08
  • UPDATE: After the feed refreshed, it looks like the hook is actually working properly, the feed is altered. Unfortunately my regex did not work properly. Some lines were removed but not the ones I wanted. – user302477 Commented Mar 11, 2019 at 14:15
Add a comment  | 

1 Answer 1

Reset to default 1

Turns out I don't need to edit the RSS at all. The lines I'm looking to remove don't originate in WP at all. They come from a Yoast SEO feature, and it can be turned off in the options: SEO -> Search Appearance -> RSS

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748812537a313930.html

最新回复(0)