WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/wp get attachment url

Contents

Description

Returns a full URI for an attachment file or false on failure.


Usage

<?php wp_get_attachment_url$id ); ?>

Default Usage

<?php echo wp_get_attachment_url( 12 ); ?> 

outputs something like http://example.net/wp-content/uploads/filename

Parameters

$id
(integer) (required) The ID of the desired attachment
Default: None

Return Value

(string/boolean) 
Returns URI to uploaded attachment or "false" on failure.


Notes

You can change the output of this function through the wp get attachment url filter.

If you want a URI for the attachment page, not the attachment file itself, you can use get_attachment_link.

Also refer: wp_insert_attachment, wp_upload_dir, wp_get_attachment_image_src

Change Log

Since: 2.1.0

Source File

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

Related

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.