-
-
Save oneblackcrayon/0ef1cd55e856e51fb39e8a487094d621 to your computer and use it in GitHub Desktop.
Filters images for RSS feed (Erik Teichmann)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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