Support » Plugin: OG » How to add image to each item?

  • Resolved awpu

    (@awpu)


    How can I add an image to each <item>? I’ve read the faq, but I’m still not understanding.

    I think I’m supposed to add an <enclosure> tag to each <item>, but I’m not sure how to do that using the filters provided. Or perhaps there’s another way?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Marcin Pietrzak

    (@iworks)

    Hi @awpu

    Truly speaking I do not understand your question. Could you explain what you want to achieve?

    Marcin

    Hi,

    I was able to achieve what I needed by adding the following to my functions.php file:

    // Add enclosure tag to rss feed items
    add_action( 'rss2_item', 'rss_feed_add_featured_image_enclosure_to_item' );
    function rss_feed_add_featured_image_enclosure_to_item()
    {
    	global $post;
    	if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
    		$attachment_id = get_post_thumbnail_id($post->ID);
    		$featured_image = wp_get_attachment_image_src( $attachment_id, 'post-thumbnail' );
    		$url = $featured_image[0];
    		$length = filesize(get_attached_file($attachment_id));
    		$type = get_post_mime_type($attachment_id);
    		echo '<enclosure url="' . $url . '" length="' . $length . '" type="' . $type . '" />';
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.