Site logo

Archived topic

No Image Captions in RSS Feed

8 replies · Started by Stephan on March 10, 2020

Viewing posts 1–9 of 9

Hi guys,

i'm using GP Premium with Dispatch Theme.

With your help i was able to show image captions under my featured images, but whatever i do - i cant make it to include them in my rss feed. Thats a problem because i need to display copyright infos of my pics ...

with thhe code beneath i made it to include featured images in rss-feed but the captions are missing.

could need your help with that

thanks a lot
Stephan

`add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$output = get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
$content = $output . $content;
}
}
return $content;
}

Hi there,

What code are you using to include captions? You should be able to use the same code in the filter you shared above.

Let me know :)

Hi Tom,

i found this snippet, but it doesnt work - maybe you can give me a tip...

function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content;
$content = '<div>' . get_the_post_thumbnail_caption( $post->ID  ) . '</div>' . $content;
 }
 return $content;
  }

Can you share the full function you're currently using to add featured images to the feed?

Hi Tom,

its just this snippet:

add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
$content = $output . $content;
}
}
return $content;
}

add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
    global $post;
    if( is_feed() ) {
        if ( has_post_thumbnail( $post->ID ) ){
            $output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
            $content = $output . $content;
        }
    }
    return $content;
}

What if you do this?:

add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
    global $post;
    if( is_feed() ) {
        if ( has_post_thumbnail( $post->ID ) ){
            $output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
            $output .= '<div>' . get_the_post_thumbnail_caption( $post->ID  ) . '</div>';
            $content = $output . $content;
        }
    }
    return $content;
}

Tom, you are a real genius - that was the solution

thanks a lot!!

You're welcome :)

This archived topic is closed to new replies.