wp_get_attachment_link

Filters a retrieved attachment page link.

Description

apply_filters( 'wp_get_attachment_link', (string) $a_href_esc_url_url_link_text_a, (int) $id, (string|array) $size, (bool) $permalink, (bool) $icon, (string|bool) $text ); 

Parameters (6)

0. $a_href_esc_url_url_link_text_a — Optional. (string) => "$link_text"
The href esc url url link text a.
1. $id (int)
Post ID.
2. $size (string|array)
Size of the image. Image size or array of width and height values (in that order). Default thumbnail..
3. $permalink (bool)
Whether to add permalink to image. Default false.
4. $icon (bool)
Whether to include an icon. Default false.
5. $text (string|bool)
If string, will be link text. Default false.

Usage

To run the hook, copy the example below.
  1. $a_href_esc_url_url_link_text_a = apply_filters( 'wp_get_attachment_link', $a_href_esc_url_url_link_text_a, $id, $size, $permalink, $icon, $text ); 
  2.  
  3. if ( !empty( $a_href_esc_url_url_link_text_a ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the wp_get_attachment_link callback 
  2. function filter_wp_get_attachment_link( $a_href_esc_url_url_link_text_a, $id, $size, $permalink, $icon, $text ) { 
  3. // make filter magic happen here... 
  4. return $a_href_esc_url_url_link_text_a
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'wp_get_attachment_link', 'filter_wp_get_attachment_link', 10, 6 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'wp_get_attachment_link', 'filter_wp_get_attachment_link', 10, 6 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/post-template.php  
  1. return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text );