Show Post Thumbnails in RSS Feed

Welcome mkmcst community Forum Web programming WordPress Random wordpress Show Post Thumbnails in RSS Feed

Viewing 0 reply threads
  • Author
    Posts
    • #9787
      Michael Mc
      Keymaster
      @mkmcst

      By default WordPress will only show text in your RSS feed but if you want to include your set featured image this snippet will do that.

      This will add the post’s featured thumbnail before your content in your site’s RSS feed.

       

      <?php
      //This will prepend your WordPress RSS feed content with the featured image
      add_filter('the_content', 'smartwp_featured_image_in_rss_feed');
      function smartwp_featured_image_in_rss_feed( $content ) {
        global $post;
        if( is_feed() ) {
          if ( has_post_thumbnail( $post->ID ) ){
            $prepend = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 10px;' ) ) . '</div>';
            $content = $prepend . $content;
          }
        }
        return $content;
      }
Viewing 0 reply threads
  • You must be logged in to reply to this topic.