this php below will print like this http://example.com/wp-content/uploads/2013/01/imagename.jpg with anchor text ‘DOWNLOAD’
<?php
if ( $attachments = get_children( array(
'post_type' => 'attachment',
'post_mime_type'=>'image',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
)));
foreach ($attachments as $attachment) {
echo wp_get_attachment_link( $attachment->ID, '' , false, true, 'Download');
}
?>
1.when user clicking this link, how to target in _blank or open in new tab.
2.is possible this short code combine with Javascript to make Force download link? look like bellow.
if ( $attachments = get_posts( array(
'post_type' => 'attachment',
'post_mime_type'=>'image',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
) ) );
foreach ( $attachments as $attachment ) {
echo '<a href="javascript:void(0);"
onclick="document.execCommand('SaveAs', true, '' . get_permalink( $attachment->ID ) . '');">
Download This Wallpaper</a>';
}
This is what I meant below in my response.
See if it works this way.
amek teh chages and try this
}
hope this will helpt you