Filter hook 'wp_get_attachment_link'

in WP Core File wp-includes/post-template.php at line 1712

View Source

wp_get_attachment_link

Filter Hook
Description
Filters a retrieved attachment page link.

Hook Information

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

Hook Parameters

Type Name Description
string $link_html The page link HTML output.
int|WP_Post $post Post ID or object. Can be 0 for the current global post.
string|int[] $size Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
bool $permalink Whether to add permalink to image. Default false.
bool $icon Whether to include an icon.
string|false $text If string, will be link text.
array|string $attr Array or string of attributes.

Usage Examples

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

function my_custom_filter($link_html, $post, $size, $permalink, $icon, $text, $attr) {
    // Your custom filtering logic here
    return $link_html;
}

Source Code Context

wp-includes/post-template.php:1712 - How this hook is used in WordPress core
<?php
1707  	 * @param bool         $permalink Whether to add permalink to image. Default false.
1708  	 * @param bool         $icon      Whether to include an icon.
1709  	 * @param string|false $text      If string, will be link text.
1710  	 * @param array|string $attr      Array or string of attributes.
1711  	 */
1712  	return apply_filters( 'wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr );
1713  }
1714  
1715  /**
1716   * Wraps attachment in paragraph tag before content.
1717   *

PHP Documentation

<?php
/**
	 * Filters a retrieved attachment page link.
	 *
	 * @since 2.7.0
	 * @since 5.1.0 Added the `$attr` parameter.
	 *
	 * @param string       $link_html The page link HTML output.
	 * @param int|WP_Post  $post      Post ID or object. Can be 0 for the current global post.
	 * @param string|int[] $size      Requested image size. Can be any registered image size name, or
	 *                                an array of width and height values in pixels (in that order).
	 * @param bool         $permalink Whether to add permalink to image. Default false.
	 * @param bool         $icon      Whether to include an icon.
	 * @param string|false $text      If string, will be link text.
	 * @param array|string $attr      Array or string of attributes.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 7
  • File: wp-includes/post-template.php
Related Hooks

Related hooks will be displayed here in future updates.