Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created January 12, 2014 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincornett/8390496 to your computer and use it in GitHub Desktop.
Save robincornett/8390496 to your computer and use it in GitHub Desktop.
Resize photos for email/RSS feed
<?php
/**
* 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("-150x150", "", $content); // looks for thumbail file names to replace with original file name. If your thumbnail settings are different, change this.
$content = str_replace("width=\"150\"", "", $content); // default thumbnail width. Change if needed.
$content = str_replace("height=\"150\"", "", $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