Advertisements

wp_get_attachment_link

Definition:
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {}

Retrieve an attachment page link using an image or icon, if possible.

Parameters

  • int $id: Optional. Post ID.
  • string $size: Optional, default is ‘thumbnail’. Size of image, either array or string.
  • bool $permalink: Optional, default is false. Whether to add permalink to image.
  • bool $icon: Optional, default is false. Whether to include icon.
  • string $text: Optional, default is false. If string, then will be link text.

Return values

returns:HTML content.

Defined filters

  • wp_get_attachment_link
    apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text )

Source code

function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {

	$id = intval( $id );

	$_post = & get_post( $id );



	if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )

		return __( 'Missing Attachment' );



	if ( $permalink )

		$url = get_attachment_link( $_post->ID );



	$post_title = esc_attr( $_post->post_title );



	if ( $text )

		$link_text = esc_attr( $text );

	elseif ( $size && 'none' != $size )

		$link_text = wp_get_attachment_image( $id, $size, $icon );

	else

		$link_text = '';



	if ( trim( $link_text ) == '' )

		$link_text = $_post->post_title;



	return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );

}

3685

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: