$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>hooks - Remove lines from RSS Feed|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

hooks - Remove lines from RSS Feed

matteradmin9PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far