Add custom image field to feed?
-
Hi there,
I was wundering if it’s possible to insert an image into the feed from a custom field (with ACF) instead of a featured image?
This code works for featured images:
// Add Post Thumbnails in the RSS Feed function diw_post_thumbnail_feeds($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = '<div>' . get_the_post_thumbnail($post->ID, 'thumbnail') . '<div>' . $content; } return $content; } add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds'); add_filter('the_content_feed', 'diw_post_thumbnail_feeds');
But I would like to use a custom field, so I edited the code into this:
function add_podcast_artwork_feeds($content) { global $post; $podcast_artwork = get_field('podcast_artwork_image', $post->ID); if ($podcast_artwork) { $content = '<div><img src="'. $podcast_artwork['sizes']['grid-small-square'] .'" width="200" height="200" alt="'. $podcast_artwork['alt'] .'" /></div>' . $content; } return $content; } add_filter('the_excerpt_rss', 'add_podcast_artwork_feeds'); add_filter('the_content_feed', 'add_podcast_artwork_feeds');
But I keep on getting this error:
<b>Fatal error</b>: Cannot use string offset as an array in <b>/mydomain/wp-content/themes/mytheme/lib/functions.php</b> on line <b>155</b><br />
where line 155 is:
$content = '<div><img src="'. $podcast_artwork['sizes']['grid-small-square'] .'" width="200" height="200" alt="'. $podcast_artwork['alt'] .'" /></div>' . $content;
When I try to print $podcast_artwork it just gives me the custom field id value?
What am I missing here?Thanks!
- The topic ‘Add custom image field to feed?’ is closed to new replies.