[post_media_download]

The shortcode designed to generate a download link for media associated with a post.


Product


Shortcode Attributes

There are a number of shortcode attributes available which you can use to customize the output.

  1. id – The ID of the post for which you want to generate the download link.
    • Default: The current post ID.
    • Options: Any numeric value.
  2. url – A custom URL to use for the download link.
    • Default: The media URL fetched from the post.
    • Options: Any URl.
  3. classes – Additional CSS classes to apply to the download link.

Shortcode Enclosed Content

Any content placed between [post_media_download] and [/post_media_download] will be used as a template, where {content} acts as a placeholder for the post description.


Example Usage

Example 1

[post_media_download]

Results

<a class="download-link" href="https://example.com/featured-image.jpg" target="_blank">
    <i class="far fa-arrow-alt-square-down"  aria-hidden="true"></i>
</a>
This example generate a download link for the featured media of the current post.
The default content for the link is a download icon (<i class="far fa-arrow-alt-square-down"></i>). You can change this by providing custom content within the shortcode tags.
The link opens in a new tab (target="_blank"), which is a common behavior for download links.

Example 2

[post_media_download url="https://example.com/custom-media-file.mp4" classes="btn btn-primary"]

Results

<a class="download-link btn btn-primary" href="https://example.com/custom-media-file.mp4" target="_blank">
    <i class="far fa-arrow-alt-square-down"  aria-hidden="true"></i>
</a>
This example generates a button with custom classes btn btn-primary, which, when clicked, will open the file custom-media-file.mp4 in a new tab for downloading.

Example 3

[post_media_download id="123" classes="btn btn-primary"]Download Now[/post_media_download]

Results

<a class="download-link btn btn-primary" href="https://example.com/featured-image.jpg" target="_blank">Download Now</a>
That example generates a link with custom classes btn btn-primary and the text “Download Now”. When clicked, the media file associated with the post (ID 123) will open in a new tab for downloading.