WordPress

Add Custom Fields To RSS Feed

WordPress has the ability to add custom fields to any post, these fields allow you to store extra data about the post without it having to go into the content.

You can use this data to add an extra piece of information to expand on your post.

For example if you were displaying products on your WordPress site then you would use the content area to write the product description and use the custom fields for the product code, price and ratings. This way you can display this data the same way on each product page. But custom fields won't appear in your RSS feed because this will only display your content, so you could miss important information for your RSS readers.

Here is a WordPress snippet to add to your functions.php file to display custom fields in your RSS feed.

function fields_in_feed($content) {  
    if(is_feed()) {  
        $post_id = get_the_ID();  
        $output = '<div><h3>Find me on</h3>';  
        $output .= '<p><strong>Facebook:</strong> ' . get_post_meta($post_id, "facebook_url", true) . '</p>';  
        $output .= '<p><strong>Google:</strong> ' . get_post_meta($post_id, "google_url", true) . '</p>';  
        $output .= '<p><strong>Twitter:</strong> ' . get_post_meta($post_id, "twitter_url", true) . '</p>';  
        $output .= '</div>';  
        $content = $content.$output;  
    }  
    return $content;  
}  
add_filter('the_content','fields_in_feed');
Back to top ^

Join Paulund

  • Get access to 100s of premium tutorials and downloadable content
  • Members content consists of Premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • Priority email development support
  • No ads

Here at Paulund you'll find Web Development tutorials and snippets focusing mainly on PHP, WordPress and CSS. Members will get access to premium tutorials that go into more detail about development with these languages. You will also get access to downloadable premium content based on the tutorial.

Join Paulund

Leave a Reply

Your email address will not be published. Required fields are marked *