Why P or DIV in RSS/feed code for featured image?
-
Hi, this is a PHP-code question.
When I search for the best up-to-date code to add featured image in my RSS feed, set to excerpts, (for Feedly and Mailchimp) I see there are some minor differences in the code, but I don′t understand why…This seems to be the “original” code from way back.
Is this still the best code for blog posts with excerpts and featured images? Or should I delete “the_content” and replace with “the_excerpt_rss”? Does this code exclude comments feed?
(And why float right??):<?php 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; } ?>
But I also found code modified with P, why/when to use P??
add_filter('the_excerpt_rss', 'rss_post_thumbnail'); add_filter('the_content_feed', 'rss_post_thumbnail'); function rss_post_thumbnail($content) { global $post; $content =''; if(has_post_thumbnail($post->ID)) { $content = '<p>' . get_the_post_thumbnail($post->ID , 'full') . '</p>' . get_the_excerpt(); } return $content; }
I also found it with DIV, why/when to use DIV??
add_filter('the_excerpt_rss', 'featuredtoRSS'); add_filter('the_content_feed', 'featuredtoRSS'); function featuredtoRSS($content) { global $post; if ( has_post_thumbnail( $post->ID ) ){ $content = '<div>' . get_the_post_thumbnail( $post->ID, 'large', array( 'style' => 'margin-bottom: 15px;' ) ) . '</div>' . $content; } return $content; }
All three are also different just before
} return $content;
Are they all correct?
Trying to learn…Bonus question,
is big images in the feed alright, or is there a max size for Feedly and Mailchimp? Thumbnail must be to small these days, but is large okey? Or is maybe 600 max??
- The topic ‘Why P or DIV in RSS/feed code for featured image?’ is closed to new replies.