Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.