Summaries Only in RSS Feeds With a Continue Reading Link
Sends only a short summary of each post to feed readers, whatever the Reading setting says, and ends it with a link back to the full post on your site.
Opens WPIDE on
Code
// Number of words in each automatic feed summary (posts with a written excerpt use it as is).
$wpide_feed_summary_words = 55;
// Link added after each summary. %s is replaced with the post title. Leave empty for no link.
$wpide_feed_continue_text = 'Continue reading: %s';
// Same as choosing "Excerpt" under Settings > Reading > "For each post in a feed, include".
add_filter( 'pre_option_rss_use_excerpt', function () {
return '1';
} );
add_filter( 'excerpt_length', function ( $length ) use ( $wpide_feed_summary_words ) {
return is_feed() ? max( 1, (int) $wpide_feed_summary_words ) : $length;
}, 999 );
add_filter( 'excerpt_more', function ( $more ) {
return is_feed() ? '…' : $more;
}, 999 );
add_filter( 'the_excerpt_rss', function ( $excerpt ) use ( $wpide_feed_continue_text ) {
// The RDF feed prints summaries without CDATA, so it only gets plain text.
if ( '' === $wpide_feed_continue_text || 'rdf' === get_query_var( 'feed' ) ) {
return $excerpt;
}
$text = sprintf( $wpide_feed_continue_text, wp_strip_all_tags( get_the_title() ) );
return trim( $excerpt ) . ' <a href="' . esc_url( get_permalink() ) . '">' . esc_html( $text ) . '</a>';
}, 20 );
Notes
Posts with a written excerpt use it in full; others are cut to the word count at the top. Set the link text to an empty string to leave the link out. If the "Read the Full Article" Link in Feeds snippet is also active, items get two links.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.