Possible Duplicate:
Retrieving a custom link on an attachment
I am using images on a Wordpress page to link to other pages in the site. I know how to get an attached image's file or attachment URL, but I can't figure out how to get its URL if it's linked to another page.
Take a look at here .The first image, "Women's clothes" links to a separate page in the site. I'm trying to make the caption of the attachment have the same link.
I know how I can use the filter below to alter the caption to wrap it in an anchor tag, but I don't know how actually retrieve the URL of the attachment if it links to a separate page. Anyone have any ideas?
//Change Caption output
function my_caption($output, $attr , $content) {
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<a href="#"><p class="wp-caption-text">' . $caption . '</p></a></div>';return $output;
}
add_filter('img_caption_shortcode','my_caption' , 10 , 3 );