This plugin hasn’t been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

This plugin has been closed and is no longer available for download.

Download Shortcode

Description

Have you ever linked a PDF, an mp3, image, or other kind of file because you wanted to let people download it but instead it just loads in the browser? This plugin introduces a [download] shortcode which allows you to output links that will tell the browser to download those files!

Usage

WITH ‘pretty permalinks’ enabled in Settings > Permalinks:

The following example would display as:

  • A link titled My Link
  • With a rewritten URL of http://yoursite.com/download/my_song.mp3

    [download label=”My Link”]http://yoursite.com/wp-content/uploads/my_song.mp3[/download]

The following example would display as:

  • A rewritten link titled http://yoursite.com/download/my_song.mp3

    [download]http://yoursite.com/wp-content/uploads/my_song.mp3[/download]

WITHOUT ‘pretty permalinks’ enabled in Settings > Permalinks:

The following example would display as:

  • A link titled My Other Link
  • With an exposed URL of http://yoursite.com/wp-content/force-download.php?file=uploads/my_other_song.mp3

    [download label=”My Other Link”]http://yoursite.com/wp-content/uploads/my_other_song.mp3[/download]

The following example would display as:

  • An exposed link titled http://yoursite.com/wp-content/force-download.php?file=uploads/my_other_song.mp3

    [download]http://yoursite.com/wp-content/uploads/my_other_song.mp3[/download]

Other Uses

If you wanted to use this in a php template, you could call something like:

<?php echo do_shortcode( '[download label="My Label"]http://example.com/wp-content/uploads/my_song.mp3[/download]' ); ?>

Important notes:

  1. If your server permissions allow it, the plugin will automatically attempt to copy force-download.php to your /wp-content/ directory.
  2. If your server permissions DO NOT allow it, you will need to manually upload the file located in /download-shortcode/wp-content/force-download.php to your /wp-content/ directory.
  3. By default, forced-download links only support files located in your uploads directory. More about this in Other Notes.

Installation

  1. Upload the entire download-shortcode folder to the /wp-content/plugins/ directory
  2. The plugin will automatically attempt to copy force-download.php into your /wp-content/ folder, though you may need to upload it manually if your server lacks the necessary permissions.
  3. Activate the plugin through the ‘Plugins’ menu in the Dashboard.

FAQ

Which file formats does this work with?

Currently, this plugin can force downloads for pdf, mp4, mp3, gif, png, jpg and jpeg files

When I click links from the front-end, all I get is a 404 Page Not Found error or a white screen. What gives?

There are two things you should check:
* There may be a problem with the force-download.php script located in your /wp-content/ directory. Try copying the force-download.php file from download-shortcode/inc/force-download.php to your wp-content directory.
* It is also possible you just need to flush your rewrite rules by visiting the Settings > Permalinks screen in your Dashboard.

How can I modify this plugin’s default behavior?

Check out the Other Notes section for example functions and filters.

I’ve uninstalled Download Shortcode but now I have a bunch of broken shortcodes in my posts and pages. How can I hide them?

You can add the following function to your theme’s functions.php file to hide all instances of the [download] shortcode in your content.

function hide_download_shortcodes( $attr, $content ) {
    return;
}
add_shortcode( 'download', 'hide_download_shortcodes' );

Contributors & Developers

“Download Shortcode” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Download Shortcode” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.1

  • Add support for WordPress in a subdirectory
  • Regenerate pot file to include translatable strings
  • TODO: Add Multisite upload directory support

1.0

  • Complete plugin rewrite
  • Introduce URL rewriting if ‘pretty permalinks’ are enabled
  • Add logic to make overwriting/updating/removing force-download.php more automated
  • Add fds_rewrite_urls filter to allow disabling URL rewriting
  • Add fds_download_rewrite_path filter to allow changing the rewrite endpoint
  • Add fds_upload_rewrite_path filter to allow changing the supported directory
  • Make the plugin translatable

0.2.3

  • Update readme.txt with note about replacing force-download.php in wp-content with the new one

0.2.2

  • Remove faulty strlen check on filenames in force-download.php
  • Fixes for WSOD issues.

0.2

  • Fix security vulnerability which exposed php core files to direct download
  • Adds phpDoc blocks
  • Add fds_download_link_class filter to change download link class
  • Other minor tweaks

0.1

  • Initial release