• 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 post brought to you by RocketGeek, ButlerBlog, and the following:

 

/*
 * 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

  • Bitnami WordPress Autoptimize cannot write to the cache directory
  • Create and delete WordPress sites in XAMPP with a batch file
  • How to fix “Error: MySQL Shutdown Unexpectedly” in XAMPP control panel
  • Fix missing Customizer in WordPress 6
  • Use Proofy.io API to validate WordPress registrations

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