I'm trying to remove 6 lines from my RSS feed using preg_replace. I've tested the regex online and it seems to select the lines properly. Somehow the lines are not getting deleted
add_action('the_content_feed', 'remove_rss_links');
function remove_rss_links($content) {
return preg_replace(".*appeared first on.*$", "", $content);
}
Here is part of the feed I'm trying to tweak.
<category><![CDATA[General]]></category>
<guid isPermaLink="false">/?p=38</guid>
<description><![CDATA[<p>Below is the directive the committee gave to our architect (Ron Garl) relative to tee renovation: Number “6” tees Must be an option for all holes New “6” tee construction on holes: 1,4,6,8,9, and … <a class="more-link" href="/">Continue reading <span class="meta-nav">→</span></a></p>
<p>The post <a rel="nofollow" href="/">Tees</a> appeared first on <a rel="nofollow" href="">Golf Course Renovation</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="/">Tees</a> appeared first on <a rel="nofollow" href="">Golf Course Renovation</a>.</p>
]]></content:encoded>
Any help with my preg_replace would be appreciated.
I'm trying to remove 6 lines from my RSS feed using preg_replace. I've tested the regex online and it seems to select the lines properly. Somehow the lines are not getting deleted
add_action('the_content_feed', 'remove_rss_links');
function remove_rss_links($content) {
return preg_replace(".*appeared first on.*$", "", $content);
}
Here is part of the feed I'm trying to tweak.
<category><![CDATA[General]]></category>
<guid isPermaLink="false">http://heronsglengolf/?p=38</guid>
<description><![CDATA[<p>Below is the directive the committee gave to our architect (Ron Garl) relative to tee renovation: Number “6” tees Must be an option for all holes New “6” tee construction on holes: 1,4,6,8,9, and … <a class="more-link" href="http://heronsglengolf/tees/">Continue reading <span class="meta-nav">→</span></a></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>
<content:encoded><![CDATA[<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>
]]></content:encoded>
Any help with my preg_replace would be appreciated.
As you said in your comment:
I only want to remove 2 per post.For each post I get a line tht reads "The Post xxx appeared first on xxx" at the bottom of both the excerpt and full text.
I'm glad you said so, regular expressions and XML parsing aren't the nicest to deal with, but it turns out you don't need to use either. This isn't a WP feature but a Yoast SEO feature, and it can be turned off in the options:
preg_replace
as an example of what you've tried. Otherwise a lot of people will see that, think "eek regex" and avoid it. Now that I know it's the post appeared first on xxx that you're trying to remove, that's actually a much easier question that probably doesn't need the XML filtering at all – Tom J Nowell ♦ Commented Mar 12, 2019 at 14:03