Having two RSS Feed URLs for WordPress

I am using MailChimp for my self hosted WordPress blog. MailChimp fetches RSS feeds for it’s email templates. I want to add small thumbnail with excerpts in RSS feed so that they appear on MailChimp’s email template but I do not want to modify the original RSS feed URL. I want to have a different URL for feeds modified for MailChimp like this: mysite.com/mailchimpfeed where as the original mysite.com/feed remains unchanged.

What will be the best way to do this?

Related posts

Leave a Reply

1 comment

  1. 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.