Created
August 14, 2014 00:32
-
-
Save davemac/a8c2b3eead05c859ecbe to your computer and use it in GitHub Desktop.
Add custom RSS feed to Wordpress
This file contains 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
function get_me_the_email_feed_template() { | |
add_filter('the_content_feed', 'css_tricks_super_awesome_feed_image_magic'); | |
include(ABSPATH . '/wp-includes/feed-rss2.php' ); | |
} | |
function css_tricks_super_awesome_feed_image_magic($content) { | |
// Weirdness we need to add to strip the doctype with later. | |
$content = '<div>' . $content . '</div>'; | |
$doc = new DOMDocument('1.0', 'utf-8'); | |
$doc->LoadHTML('<?xml encoding="UTF-8">' . $content); | |
$images = $doc->getElementsByTagName('img'); | |
foreach ($images as $image) { | |
$image->removeAttribute('height'); | |
$image->setAttribute('width', '320'); | |
} | |
// Strip weird DOCTYPE that DOMDocument() adds in | |
$content = substr($doc->saveXML($doc->getElementsByTagName('div')->item(0)), 5, -6); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment