WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/rss2 item

Description

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.

Example Usage

Adds an image node to your RSS2 feeds.

<?php
add_action('rss2_item', 'add_my_rss_node');

function 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;
}
?>

Adds a node from a custom field to your RSS2 feeds using get_post_meta()

<?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;
}
?>

Related

rss_item action hook, atom_item action hook, rdf_item action hook, commentrss2_item action hook, comment_atom_entry action hook

See also

This page is marked as incomplete. You can help Codex by expanding it.