Skip to content

Instantly share code, notes, and snippets.

@elhardoum
Created October 12, 2017 22:43
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 elhardoum/95a15f64d9ace6eac07f31868595a443 to your computer and use it in GitHub Desktop.
Save elhardoum/95a15f64d9ace6eac07f31868595a443 to your computer and use it in GitHub Desktop.
https://samelh.com/blog/?p=582 - Tweak MailChimp RSS Feeds to add the featured image, excerpt and a read more button.
<?php
/*
Plugin Name: Tweak MailChimp Feeds RSS
Plugin URI: https://samelh.com/blog
Description: Tweak MailChimp RSS Feeds to add the featured image, excerpt and a read more button.
Author: Samuel Elh
Version: 0.1
Author URI: https://go.samelh.com/buy-me-a-coffee
*/
defined ( 'ABSPATH' ) || exit ( 'Direct access not allowed.' . PHP_EOL );
$GLOBALS['feed_ignore_categories'] = array(
/**
* To ignore posts from certain categories,
* enter your category IDs here separated by commas. example
* 2, 19, 28
*/
);
function filter_the_content_feed( $content ) {
global $post;
$featured_image = has_post_thumbnail($post) ? get_the_post_thumbnail($post) : null;
$excerpt = trim( wpautop(get_the_excerpt( $post->ID )) );
$read_more = '<table border="0" cellpadding="0" cellspacing="0" style="margin: 0 auto;background-color:#25aae2; border-radius:5px;">';
$read_more .= '<tr>';
$read_more .= '<td align="center" valign="middle" style="color:#FFFFFF; font-family:Helvetica, Arial, sans-serif; font-size:16px; font-weight:bold; letter-spacing:-.5px; line-height:150%;">';
$read_more .= '<a href="' . get_the_permalink($post) . '" target="_blank" style="padding: 15px 30px; line-height: 40px;color:#FFFFFF; text-decoration:none;">Read More</a>';
$read_more .= '</td>';
$read_more .= '</tr>';
$read_more .= '</table>';
return $featured_image . $excerpt . $read_more;
}
function pre_get_posts_mailchimp_rss($query) {
$query->query_vars['category__not_in'] = $GLOBALS['feed_ignore_categories'];
}
if ( isset($_REQUEST['mailchimp_feed_rss']) ) {
remove_all_filters('the_content');
add_filter('wpseo_include_rss_footer', '__return_false');
add_action('pre_get_posts', 'pre_get_posts_mailchimp_rss');
add_filter( 'the_excerpt_rss', 'filter_the_content_feed', 999 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment