Remove Images From Feed Content
Strips images and image captions from the content sent in your feeds, keeping feeds light for readers and services that only want the text.
Opens WPIDE on
Code
$wpide_strip_feed_images = function ( $content ) {
$content = preg_replace( '/<figure[^>]*>\s*(?:<a[^>]*>)?\s*<img[^>]*>\s*(?:<\/a>)?\s*(?:<figcaption.*?<\/figcaption>)?\s*<\/figure>/is', '', $content );
$content = preg_replace( '/<img[^>]*>/i', '', (string) $content );
return (string) $content;
};
add_filter( 'the_content_feed', $wpide_strip_feed_images, 30 );
add_filter( 'the_excerpt_rss', $wpide_strip_feed_images, 30 );
Notes
The featured image added by other feed snippets is not affected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.