Filter hook 'attachment_link'

in WP Core File wp-includes/link-template.php at line 534

View Source

attachment_link

Filter Hook
Description
Filters the permalink for an attachment. the view attachment page link on the media modal.

Hook Information

File Location wp-includes/link-template.php View on GitHub
Hook Type Filter
Line Number 534

Hook Parameters

Type Name Description
string $link The attachment's permalink.
int $post_id Attachment ID.

Usage Examples

Basic Usage
<?php
// Hook into attachment_link
add_filter('attachment_link', 'my_custom_filter', 10, 2);

function my_custom_filter($link, $post_id) {
    // Your custom filtering logic here
    return $link;
}

Source Code Context

wp-includes/link-template.php:534 - How this hook is used in WordPress core
<?php
 529  	 *              the view attachment page link on the media modal.
 530  	 *
 531  	 * @param string $link    The attachment's permalink.
 532  	 * @param int    $post_id Attachment ID.
 533  	 */
 534  	return apply_filters( 'attachment_link', $link, $post->ID );
 535  }
 536  
 537  /**
 538   * Retrieves the permalink for the year archives.
 539   *

PHP Documentation

<?php
/**
	 * Filters the permalink for an attachment.
	 *
	 * @since 2.0.0
	 * @since 5.6.0 Providing an empty string will now disable
	 *              the view attachment page link on the media modal.
	 *
	 * @param string $link    The attachment's permalink.
	 * @param int    $post_id Attachment ID.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/link-template.php
Related Hooks

Related hooks will be displayed here in future updates.