do_action( 'rss2_item' )

Fires at the end of each RSS2 feed item.


More Information More Information

The rss2_item action hook is triggered immediately after the default output of an rss2 feed.

This hook has no parameters and no return values. It can be used to echo data into the feed if necessary.

This hook is not dependent on your theme. It can be called within your theme’s functions.php file or from a plugin.


Top ↑

Source Source

File: wp-includes/feed-rss2.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Collins Mbaka

    Add an image element for each post

    Adds an image node to your RSS2 feeds

    add_action( 'rss2_item', 'wporg_add_my_rss_node' );
    
    function wporg_add_my_rss_node() {
    	global $post;
    	if ( has_post_thumbnail( $post->ID ) ) :
    		$thumbnail = get_attachment_link( get_post_thumbnail_id( $post->ID ) );
    		echo "<image>{$thumbnail}</image>";
    	endif;
    }
    
  2. Skip to note 2 content
    Contributed by Akira Tachibana

    (From Codex)
    Add a custom field element for each post
    Adds a node from a custom field to your RSS2 feeds using get_post_meta().

    Note: Custom elements like the one in this example are not a part of the RSS 2.0 specification, so adding it will mean your feed will technically be invalid RSS 2.0. Few, if any, RSS readers will make any use of the custom element.

    <?php
    add_action('rss2_item', 'add_my_custom_field_node');
    
    function add_my_custom_field_node() {
    	global $post;
    	$metaValue = get_post_meta($post->ID, 'my-custom-field', true);
    	if(!empty($metaValue)):
    		echo("<my-custom-field>{$metaValue}</my-custom-field>");
    	endif;
    }
    ?>

You must log in before being able to contribute a note or feedback.