admin管理员组文章数量:1415491
I want to add image from post content in my rss feed but all the tutorials that I find are only for featured image. I want image from post content and not featured image. How can I do this?
I want to add image from post content in my rss feed but all the tutorials that I find are only for featured image. I want image from post content and not featured image. How can I do this?
Share Improve this question asked Mar 11, 2017 at 13:18 TravelWhereTravelWhere 1812 silver badges11 bronze badges3 Answers
Reset to default 0Here is the link I found a solution. How to display featured post thumbnails in WordPress feeds
paste this code snippet in your theme functions.php file
// display featured post thumbnails in WordPress feeds
function wcs_post_thumbnails_in_feeds( $content ) {
global $post;
if( has_post_thumbnail( $post->ID ) ) {
//if you want to show thumbnail image
$content = '<figure>' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '</figure>' . $content;
// if you want to show full image
//$content = '<p>' . get_the_post_thumbnail( $post->ID,'full' ) . '</p>' . $content;
//if you want to custom image using add_image_size()
//$content = '<figure>' . get_the_post_thumbnail( $post->ID, 'custom-image-size' ) . '</figure>' . $content;
}
return $content;
}
add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' );
add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );
This is the concepts how to you show external link image. How you fetch the external image, it upon you.
it's showing all the post same image. Just change image link for each post. ex: src="'.$image_url.'"
function rss_feed_from_external_link( $content ) {
global $post;
$content = '<figure><img width="150" height="128" src="https://www.google/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" sizes="100vw" /></figure>' . $content;
return $content;
}
add_filter( 'the_excerpt_rss', 'rss_feed_from_external_link' );
add_filter( 'the_content_feed', 'rss_feed_from_external_link' );
Image showing for custom field.
add_filter('the_content', 'custom_fields_for_feeds');
add_filter('the_meta','custom_files_for_feed');
function custom_fields_for_feeds( $content ) {
global $post;
global $post;
// Get the custom fields ***
// Checks for thumbnail
$image = get_post_meta($post->ID, 'Thumbnail', $single = true);
// Checks for thumbnail alt text
$image_alt = get_post_meta($post->ID, 'Thumbnail Alt', $single = true);
if($image_alt == '') { $image_alt = 'This image has no alt text'; }
if($image !== '') {
$content = '<figure><img src="'.$image.'" alt="'.$image_alt.'" /></figure>' . $content;
return $content;
}
else {
$content = $content;
return $content;
}
add_filter('the_content', 'custom_fields_for_feeds');
add_filter('the_meta','custom_files_for_feed');
You can also use custom image fields to display in the RSS feed.
Let me know you not solve your problem.
This code is working like a charm, you can add a custom image without affecting any page (the image only shown in the RSS feed file).
function rss_feed_from_external_link( $content ) {
global $post;
$content = '<figure><img width="100%" height="auto" src="img_src" class="" alt="" /></figure>' . $content;
return $content;
}
add_filter( 'the_excerpt_rss', 'rss_feed_from_external_link' );
add_filter( 'the_content_feed', 'rss_feed_from_external_link' );
Thank you
If you want to use content images on other website or pages you may use WordPress REST API. This will help your access all data of the content.
本文标签: How to add image in rss
版权声明:本文标题:How to add image in rss? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745219547a2648326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论