1

I want to display post thumbnails and hyperlinks in post on my feed page. I know in templates you can copy page template and modify it, but here i am dealing with wp-includes/feed.php or wp-includes/feed-rss . I have two question

  1. what can i do get to get thumbnails of post and links of post?
  2. If i edit the feed template, tomorrow when wordpress updates, it will remove my custom code, how can i make it like a child-template, so my code doesn't get disturbed, when new updates come.

1 Answer 1

0

you don't need to edit WordPress core files and don't do this, when hooks are available to modify use the_excerpt_rss and the_content_feed filter to add thumbnails or your custom links in feed.

add_filter( 'the_excerpt_rss', 'insert_thumbnail_into_feed' );
add_filter( 'the_content_feed', 'insert_thumbnail_into_feed' );

function insert_thumbnail_into_feed() {
    global $post;
    if ( has_post_thumbnail( $post->ID ) ){
        // replace thumbnail with yours
        $content = '<p>' .get_the_post_thumbnail( $post->ID, 'thumbnail' ) .'</p>';
    }

    // get post content and replace feed content with
    // you can also limit/filter the content to exclude shortcodes and html code etc.
    $content .= '<p>' .get_the_content() .'</p>';

    return $content;
}

EDIT: place this code in your theme's functions.php

6
  • By hyperlink i meant, that any link in the post, comes as a hyperlink in rss too.Will it return the way i described above?
    – localhost
    Commented Sep 13, 2013 at 20:30
  • oh i see, then you need to replace feed content with yours. wait i am going to edit my answer.
    – Anjum
    Commented Sep 13, 2013 at 21:05
  • Also i see, this will show up in rss2 or atom? how do i make the feed by default to the one which shows that thumbnails, and hyperlink
    – localhost
    Commented Sep 13, 2013 at 21:08
  • any help. still waiting for the answer to be updated.
    – localhost
    Commented Sep 13, 2013 at 21:58
  • @Nofel i have updated answer about 9 hours ago, but was forget to notify you about changes, please copy and paste code into your functions.php
    – Anjum
    Commented Sep 14, 2013 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.