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

---

# apply_filters( ‘attachment_link’, string $link, int $post_id )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/attachment_link/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/attachment_link/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/attachment_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/attachment_link/?output_format=md#changelog)

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

Filters the permalink for an attachment.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/attachment_link/?output_format=md#parameters)󠁿

 `$link`string

The attachment’s permalink.

`$post_id`int

Attachment ID.

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

    ```php
    return apply_filters( 'attachment_link', $link, $post->ID );
    ```

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

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

| Used by | Description | 
| [get_attachment_link()](https://developer.wordpress.org/reference/functions/get_attachment_link/)`wp-includes/link-template.php` |

Retrieves the permalink for an attachment.

  |

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

| Version | Description | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Providing an empty string will now disable the view attachment page link on the media modal. | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## User Contributed Notes

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