Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created November 19, 2020 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Archie22is/a3f9f479fab6c7169e0abad88b2cd999 to your computer and use it in GitHub Desktop.
Save Archie22is/a3f9f479fab6c7169e0abad88b2cd999 to your computer and use it in GitHub Desktop.
Filters images for RSS feed (Erik Teichmann)
/**
* Filters images for RSS feed--makes thumbs go through large; large images resize down to MailChimp friendly width.
* Add this to your functions.php file WITHOUT the opening php
*
* Author: Erik Teichmann, minor tweaks by Robin Cornett
* Author URI: http://www.eriktdesign.com/
*/
// Add filters for RSS
add_filter('the_excerpt_rss', 'et_change_thumbs', 20); // changes the excerpt for rss
add_filter('the_content', 'et_change_thumbs', 20); // changes the content
function et_change_thumbs($content) {
// See if we're dealing with a feed
if ( is_feed() ) { // if you're on an RSS feed, do this.
// Strip out the parts of img src that lead to thumbnails
$content = str_replace("-310x310", "", $content); // looks for thumbail file names to replace with original file name. If your thumbnail settings are different, change this.
$content = str_replace("width=\"310\"", "", $content); // default thumbnail width. Change if needed.
$content = str_replace("height=\"310\"", "", $content); // default thumbnail height. Change if needed.
$content = str_replace("class=\"attachment-thumbnail\"", "style=\"max-width:560px\"", $content); // looks for thumbnail class, resizes to 560px, a MailChimp friendly size (factoring in email on margin)
$content = str_replace("width=\"700\"", "style=\"max-width:560px\"", $content); // replaces 700px wide images and makes them smaller. replace 700 with your image size.
}
// Send the content on its way
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment