• Resolved paulw1

    (@paulw1)


    Hi there,

    I need to add the Featured Images for each post into my RSS feed, preferably as a new node (something like ‘thumbnail’) with just the image url.

    I’ve seen multiple solutions to this for wordpress 2.9 (e.g. this) but have yet to find a solution that works in 3.0. I’m not sure why those solutions no longer work, but if anyone has any ideas they would be greatly appreciated.

    Thanks in advance

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter paulw1

    (@paulw1)

    Managed to solve this myself by hacking around with feed-rss2.php under /wp-includes/ (in WordPress 3.0), thought I’d post it here in case it’s of use to anyone.

    I ended up using a traditional custom field instead of the Featured Image so that I could simply access an image URL.

    I added the below code to the rss file as a new node under <item>:

    <?php
      $key="project-thumb";
      if ( get_post_meta($post->ID, $key, true) ): ?>
        <thumbnail><?php echo get_post_meta($post->ID, $key, true); ?></thumbnail>
      <?php endif;
    ?>

    in this case my custom field is ‘project-thumb’, the code checks whether the field has a value or not and if it does it adds the image url (the content of the custom field) as a new node thumbnail.

    Hope this helps some people, had me stumped for a while

    For ease-of-use for non-technically inclined contributors, I’d prefer to not use a custom field.

    Any further thoughts on how to call the Featured Image itself?

    Phil

    (@owendevelopment)

    I’d like to know this also.

    not just in the main feed (domain.com/feed)

    … but also in the category feeds (domain.com/category/feed)

    Any ideas anyone?

    // THIS INCLUDES THE THUMBNAIL IN OUR RSS FEED
    function insertThumbnailRSS($content) {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
    $content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail' ) . '' . $content;
    }
    return $content;
    }
    
    add_filter('the_excerpt_rss', 'insertThumbnailRSS');
    add_filter('the_content_feed', 'insertThumbnailRSS');

    This works fine for me on 3.0.1 to include thumbnail/featured image in RSS feed

    Phil

    (@owendevelopment)

    Hi Rev.

    This works fine for the main RSS, but not for the category feeds. No images appear in any of those.

    Hi guys, I have the solution for your problems.

    This is the code for the RSS files that you use, in my case “/ wp-includes/feed-rss2.php”

    search in file “<? php the_excerpt_rss ()?>” and add the code just before: “<? php echo ‘<img src=”‘.get_first_image().'” height=”150″ alt=”” />’ ;?> “. This should be done for every “<? php the_excerpt_rss ()?>” in the file.

    In the event that your theme hasn’t the function of seeking the first image of each post is also modified another file, “/ wp-includes/functions.php” which must be added immediately: “get_first_image function () (
    global $ post, $ posts;
    $ First_img =”;
    $ Output = preg_match_all (‘/ <img.+src=[\'”]([^\'”]+)[\'”].*> s’, $ post-> post_content, $ matches);
    First_img $ = $ matches [1] [0];
    return $ first_img;
    )

    Omit the commas of course. Ps “The feed is not updated immediately, try to see the feed of a category and see the result”

    Sorry for my english ;=)

    Rizzus

    It’s not a problem with your English, but with your coding…

    How many times have you seen a function definition start like this:

    get_first_image function ()

    ?

    Or used standard brackets to encapsulate the function instead of curly brackets?

    Major eyeroll.

    Here is what I have. I made a few changes since I wanted the image address to appear as a separate node:

    First, in /wp-includes/functions.php, add this to the bottom BEFORE the ending ?>

    function get_first_image() {
    	global $post, $posts;
    
    	$result = preg_split("/\"/", get_the_post_thumbnail( $post->ID, 'thumbnail' ));
    	return $result[1];
    }

    Then in /wp-includes/feed-rss2.php, add the following anywhere within the <item>…</item> area. For example, I added it below the <comments>…</comments>:

    <?php if (get_the_post_thumbnail( $post->ID, 'thumbnail' ) != '') { ?>
    		<featured-image><?php echo new_first_image(); ?></featured-image>
    <?php } ?>

    This will cause a new node to be added to the RSS tree. Hope this works.

    @rev. Voodoo – Your solution works great. If I wanted to align the image right or left, IE – add a style to it, how would I do that? Thanks so much for the help

    Never mind, I got it.

    Add this to your functions.php

    // THIS INCLUDES THE THUMBNAIL IN OUR RSS FEED
    function insertThumbnailRSS($content) {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
    $content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'alt' => get_the_title(), 'title' => get_the_title(), 'style' => 'float:right;' ) ) . '' . $content;
    }
    return $content;
    }
    add_filter('the_excerpt_rss', 'insertThumbnailRSS');
    add_filter('the_content_feed', 'insertThumbnailRSS');

    None of the above options puts anything in my RSS feed. Putting Voodoo’s function in my functions.php shuts down my site and gives me a white page. The others simply don’t do anything at all for me. I have WordPress 3.0.4

    I would never have though putting images in an RSS feed would be sooooo difficult. The only plugin on the net right now that does anything is this one by Kafkaesqui:

    http://wordpress.org/support/topic/line-breaks-in-rss-feed#post-356315

    and even that one just puts the url to the image in the feed and not the image. How can I get this to work?

    I wonder if it’s because I use a plugin that is expired to obtain my custom field images.

    http://scribu.net/wordpress/custom-field-images

    Found the problem. I was putting the code into includes/functions.php but it has to go in the functions.php found in your theme’s directory. A slight detail that was overlooked.

    Just came across this, ran into a similar situation and wanted to say, “Rev. Voodoo” has the optimal solution.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Thumbnails/Featured Images in RSS Feed in 3.0’ is closed to new replies.