WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What filters can I use to remove specific HTML elements with certain classes from the Wordpress feed? Not remove everything inside the element, mind you, but just remove the markup itself.

For example:

<div class="remove-this class1 class2 class3">
    <img class="remove-this class4 class5 class6" />
    <p>Yada yada bla bla whatever dummy text</p>
    <img class="class7" />

The result should be:

<p>Yada yada bla bla whatever dummy text</p>
<img class="class7" />

Why? We have a syndication agreement with a big web portal. They will get articles from our feed and automatically put it in their CMS.

The problem is that I've used shortcodes to allow varied multi-column layouts, which won't work properly because the CSS I defined for the layouting is of course not available on the web portal. The shortcodes resolve into divs with specific classes attached to them.

The trick is of course removing the trailing elements for those that have opening and closing tags, without touching the content wrapped inside. Thus I'm not sure if Regex is the best (and most efficient) approach here.

share|improve this question

Use the filter the_content_feed. He is explizit for change content, before sending in feed.

A small example. Include a regex or replacement function to get your goal on content.

add_filter( "the_content_feed", "fb_example_change_content_feed" );
function fb_example_change_content_feed( $content ) {

   $content .= 'Total ' . str_word_count( $content ) . ' words';

   return $content;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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