Description
A shortcode that enables displaying a link to download any single attachment available in Media Library, inside posts content or manual attachments display anywhere in a theme.
Usage
[download-attachment id="17" title="Download title" class="button button-primary"]
Attributes
- id | int – an attachment ID (required)
- title | string – attachment link title, defaults to attachment title
- class | string – link class, defaults to “da-download-link da-download-attachment-$id”, where $id is an attachment id
Attachment attributes can be adjusted with the da_download_attachment_link_attributes filter hook:
// Adjust link attributes for specific attachments
function custom_da_download_attachment_link_attributes( $attr, $attachment_id ) {
if ( $attachment_id != 12 ) {
$attr['data-attachment_id'] = $attachment_id;
}
return $attr;
}
add_filter( 'da_download_attachment_link_attributes', 'custom_da_download_attachment_link_attributes', 10, 2 );