简体   繁体   中英

Including thumbnail captions in RSS feed

Do you know the best way to incorporate the function the_post_thumbnail_caption into a function that gets thumbnail posts for the RSS feed? I am working on a project that requires having captions of thumbnail images populating on an RSS feed and appreciate your time shared on this inquiry.

In other words, I would like to include get_the_post_thumbnail_caption function in this:

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;
}
return $content;
}

Would is be best to use the && operator?

I was able to solve what I was trying to do, if anyone is trying to add captions from thumbnails to their RSS feed all you need to do is add get_the_post_thumbnail_caption like this:

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;
  }

Please chime in if there is a more effective way to do this, I am always looking for better practices!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM