If someone can help to remove a div from my RSS feed. I want to remove below code from my RSS feed.

<div class="well"> <a class="btn" href="foo.com">foo</a></div>

Thanks in advance, Gregory

1 Answer 1


You can use the_content_feed hook for that. It is used to filter the content of the post after it is retrieved from the database and filtered by "the_content" and before it is sent to RSS reader (or browser).

So here's the code:

add_filter( 'the_content_feed', function ( $content ) {
    $content = str_replace( '<div class="well"> <a class="btn" href="foo.com">foo</a></div>', '', $content );
    return $content;
} );
  • Hello Krzysiek Dróżdż, unfortunately the code doesn't work for me.
    – veggera
    Feb 28, 2019 at 21:49
  • Remember that feeds are cached by browsers - so most of the time you have to force-refresh them... Also make sure that the str_replace replaces exactly what you want. Feb 28, 2019 at 21:53
  • The point is, if I change the content of the feed on new post I can see directly the new changes, also i use W3TC with rss purge settings on every new post. Many thanks for your help Krzysiek.
    – veggera
    Feb 28, 2019 at 22:00
  • OK, so check two things. 1. Change return $content; to return $content . 'adfkjslfjdlasd'; - do you see 'adfkjslfjdlasd' in the feed? 2. Change 'the_content_feed' to 'the_content' - do you see the div removed directly on the site? Feb 28, 2019 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.