Sponsor Message Inside Feed Items
Places a short sponsor or promotion message after the first paragraph of every item in your feeds, where RSS readers and RSS-to-email newsletters will show it.
Opens WPIDE on
Code
// Message placed after the first paragraph of each feed item (HTML allowed). Empty = off.
// Example: 'This newsletter is supported by <a href="https://example.com/">Example Co</a>.'
$wpide_feed_message = '';
// Limit to posts in these category slugs; empty = all posts.
$wpide_feed_message_categories = array();
add_filter( 'the_content_feed', function ( $content ) use ( $wpide_feed_message, $wpide_feed_message_categories ) {
if ( '' === trim( $wpide_feed_message ) || ( $wpide_feed_message_categories && ! in_category( $wpide_feed_message_categories ) ) ) {
return $content;
}
$box = '<p style="padding:12px;border-left:4px solid #ccc;background:#f6f7f7;"><em>' . wp_kses_post( $wpide_feed_message ) . '</em></p>';
$pos = stripos( $content, '</p>' );
return false === $pos ? $content . $box : substr_replace( $content, '</p>' . $box, $pos, 4 );
} );
Notes
Nothing is added until you write the message; you can limit it to posts in certain categories.
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.