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

Function Reference/get attached file


Retrieve attached file path based on attachment ID.

You can optionally send it through the 'get_attached_file' filter, but by default it will just return the file path unfiltered.

The function works by getting the single post meta name, named '_wp_attached_file' and returning it. This is a convenience function to prevent looking up the meta name and provide a mechanism for sending the attached file name through a filter.


<?php get_attached_file$attachment_id$unfiltered ); ?>


(integer) (required) Attachment ID.
Default: None
(boolean) (optional) Whether to apply filters or not.
Default: false

Return Values

The file path to the attached file.


$fullsize_path = get_attached_file( $attachment_id ); // Full path


  • Uses: apply_filters() to call get_attached_file() on file path and $attachment_id.
  • Uses: get_post_meta() on $attachment_id, the '_wp_attached_file' meta name.

Change Log

Since: 2.0.0

Source File

get_attached_file() is located in wp-includes/post.php.


Attachment Functions:

get_children(), get attached media(), the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()

See also index of Function Reference and index of Template Tags.