Basic MailChimp feed:
Here's one simple idea:
/**
* Basic MailChimp feed
*
* Example: domain.com/mailchimpfeed
*/
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'do_feed_rss2' );
}
add_action('init', 'mailchimp_feed' );
to reuse the native RSS2 feed, under a different url.
MailChimp feed with featured images:
If we want to add the featured images to the MailChimp feed, we can use:
/**
* MailChimp feed with featured images
*
* Example: domain.com/mailchimpfeed
*/
add_action('init', 'mailchimp_feed' );
function mailchimp_feed()
{
add_feed( 'mailchimpfeed', 'mailchimp_feed_template' );
}
function mailchimp_feed_template()
{
add_action( 'rss2_item', 'mailchimp_media_item' );
add_action( 'rss2_ns', 'mailchimp_ns' );
do_feed_rss2();
}
function mailchimp_ns()
{
print 'xmlns:media="http://search.yahoo.com/mrss"';
}
function mailchimp_media_item()
{
if( has_post_thumbnail( get_the_ID() ) )
$image = array_shift( wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ) ) );
else
$image = sprintf( '%s/default.jpg', get_site_url() );
printf( '<media:content url="%s/default.jpg" medium="image" />', $image );
}
We can then modify the featured image size to our needs and the default image if there's no one set.
Flush rewrite rules once to activate:
In both cases we just have to remember to flush the permalinks settings to activate the custom MailChimp feed.
--
Hope this helps.