• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / Code Snippets / Promote your RSS feed on every post

Promote your RSS feed on every post

October 21, 2020

/*
 * This demo uses the_content filter to add an RSS
 * link to the end of every post.
 *
 * @uses the_content
 * @uses is_single()
 * @uses get_bloginfo() DO NOT use bloginfo() because it "echos" content immediately.
 *
 * @link https://developer.wordpress.org/reference/hooks/the_content/
 * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
 * @link https://developer.wordpress.org/reference/functions/is_single/
 * @link https://codex.wordpress.org/Conditional_Tags
 * @link https://developer.wordpress.org/reference/functions/get_bloginfo/
 *
 * I used a custom class of "promote_my_rss" for the div wrapper.
 * You can make this whatever you'd like based on your available
 * styles.
 */
add_filter( 'the_content', function ( $content ) {
    if ( is_single() ) {
        $content .= '<div class="promote_my_rss"> 
            <h3>Enjoyed this article?</h3> 
            <p>
                Don\'t miss a single post. Subscribe to our 
                <a class="feed" href="' . get_bloginfo( 'rss2_url' ) . '" title="Subscribe via RSS">RSS feed!</a>
            </p>
        </div>';
    }
    return $content;
});

Chad Butler

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Block an IP address from accessing your site
  • Using WordPress Debug Constants
  • Save WordPress debug log by date
  • Utility function for the WordPress error log
  • How to Create a Site Specific Plugin

Copyright © 2021 · Maker Pro on Genesis Framework · WordPress · Log in