0

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" />
</div>

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.

1 Answer 1

0

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;
}
1
  • Sorry it took me a while to get back, but this is exactly what I did. Thank you!
    – ricotheque
    Nov 23, 2016 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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