Make MP3 And Pdf Files Downloadable

Download music

In my recent project for a client, the client wants the MP3 file to be downloaded automatically when users click on the link. Usually, when users click on an MP3 link, what will happen is it will be redirected to a new window. Then, to download the MP3, they will need to right click, and choose Save As to download the MP3 file to their machine.

This is not so user-friendly.

Then I began to search on the internet. Some folks on the WordPress support forum suggested tweaking the .htaccess. I tried few of them, none works!

So, what is the solution?

I came across this cool WordPress plugin called Shortcode Download plugin. Besides making the MP3 file downloadable, this can also be used for Pdf file and image. When users click on the link to the file, it will force-download it rather than open the file to a new window.

How To Use Shortcode Download plugin

1. Download the Shortcode Download plugin from the WordPress plugin repo. Read my previous article on How To Install a WordPress plugin.

2. After Installing the plugin, you will need to use the shortocode in your post or page.

3. By default, download links only support files located in your uploads directory. When you upload the file, it will be uploaded to your /wp-content/uploads/ directory.

4. By default, the uploaded file will be rewrite with /download/ path. For example, your song1.mp3 file will be rewrite to yourdomain.com/downloads/song1.mp3.

5. Luckily, the developer has provided few useful filters to be used with this plugin. To change the directory from /uploads/ to /mp3/, you can use the filter below:

[php]
function change_download_files_directory() {
return ‘mp3′;
}
add_filter( ‘fds_download_files_directory’, ‘change_download_files_directory’ );
[/php]

6. To change the rewrite path from /downloads/ to something else, for example /tools/, you can simple use the filter below:

[php]
function change_download_rewrite_path() {
return ‘tools';
}
add_filter( ‘fds_download_rewrite_path’, ‘change_download_rewrite_path’ );
[/php]

7. Please see the Other Notes tab on the plugin page for more information.

This plugin has been rewritten for better security and performance. If you find any issues with this plugin, please put your questions in the support forum. I found the developer of this plugin to be quite useful and fast in making response to users.

What’s your thought? Do you have any better solutions?

Leave a Reply

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