Title: rss_enclosure
Published: April 25, 2014
Last modified: April 28, 2025

---

# rss_enclosure()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#wp--skip-link--target)

Displays the rss enclosure for the current post.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#description)󠁿

Uses the global $post to check whether the post requires a password and if the user
has the password for the post. If not then it will return before displaying.

Also uses the function [get_post_custom()](https://developer.wordpress.org/reference/functions/get_post_custom/)
to get the post’s ‘enclosure’ metadata field and parses the value to display the
enclosure(s). The enclosure(s) consist of enclosure HTML tag(s) with a URI and other
attributes.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#source)󠁿

    ```php
    function rss_enclosure() {
    	if ( post_password_required() ) {
    		return;
    	}

    	foreach ( (array) get_post_custom() as $key => $val ) {
    		if ( 'enclosure' === $key ) {
    			foreach ( (array) $val as $enc ) {
    				$enclosure = explode( "\n", $enc );

    				if ( count( $enclosure ) < 3 ) {
    					continue;
    				}

    				// Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'.
    				$t    = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
    				$type = $t[0];

    				/**
    				 * Filters the RSS enclosure HTML link tag for the current post.
    				 *
    				 * @since 2.2.0
    				 *
    				 * @param string $html_link_tag The HTML link tag with a URI and other attributes.
    				 */
    				echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" );
    			}
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/feed.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/feed.php#L475)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/feed.php#L475-L504)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#hooks)󠁿

 [apply_filters( ‘rss_enclosure’, string $html_link_tag )](https://developer.wordpress.org/reference/hooks/rss_enclosure/)

Filters the RSS enclosure HTML link tag for the current post.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#related)󠁿

| Uses | Description | 
| [post_password_required()](https://developer.wordpress.org/reference/functions/post_password_required/)`wp-includes/post-template.php` |

Determines whether the post requires password and whether a correct password has been provided.

  | 
| [get_post_custom()](https://developer.wordpress.org/reference/functions/get_post_custom/)`wp-includes/post.php` |

Retrieves post meta fields, based on post ID.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [absint()](https://developer.wordpress.org/reference/functions/absint/)`wp-includes/load.php` |

Converts a value to non-negative integer.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rss_enclosure/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frss_enclosure%2F)
before being able to contribute a note or feedback.