Title: atom_enclosure
Published: April 25, 2014
Last modified: May 20, 2026

---

# atom_enclosure()

## In this article

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

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

Displays the atom enclosure for the current post.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/atom_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 link HTML tag(s) with a URI and other 
attributes.

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

    ```php
    function atom_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 );

    				$url    = '';
    				$type   = '';
    				$length = 0;

    				$mimes = get_allowed_mime_types();

    				// Parse URL.
    				if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
    					$url = trim( $enclosure[0] );
    				}

    				// Parse length and type.
    				for ( $i = 1; $i <= 2; $i++ ) {
    					if ( isset( $enclosure[ $i ] ) ) {
    						if ( is_numeric( $enclosure[ $i ] ) ) {
    							$length = trim( $enclosure[ $i ] );
    						} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) {
    							$type = trim( $enclosure[ $i ] );
    						}
    					}
    				}

    				$html_link_tag = sprintf(
    					"<link href=\"%s\" rel=\"enclosure\" length=\"%d\" type=\"%s\" />\n",
    					esc_url( $url ),
    					esc_attr( $length ),
    					esc_attr( $type )
    				);

    				/**
    				 * Filters the atom 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( 'atom_enclosure', $html_link_tag );
    			}
    		}
    	}
    }
    ```

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

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

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

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

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

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

Retrieves the list of allowed mime types and file extensions.

  | 
| [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.

  | 
| [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 3 more](https://developer.wordpress.org/reference/functions/atom_enclosure/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/atom_enclosure/?output_format=md#)

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

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

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fatom_enclosure%2F)
before being able to contribute a note or feedback.