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 );

5 replies to "[download-attachment]"

  1. Hi

    is it possible to use only button on the pages? i can’t use this code cause if i’m use this, then i can’t download separate things only one ID (page.php) but i want 4 separate id in 4 separate page how can i do this?

  2. Is it possible to display single attachment’s download count? I can only display count for “download-attachments”, but not “download-attachment”. :(

    • Yes, with simple get_post_meta():

      $count = get_post_meta( $post_id, ‘_da_attachments’, true );

      where post id is the ID of an attachment you want to get downloads count for.

  3. The file to be download is 3G in size. Is it supported?

    • It should work fine in redirect to file mode. Just try that.

Leave a Reply

Please, do not use this form for technical support. To get support for our plugins, use the support forum.

Your email address will not be published. Required fields are marked *