How To Force Any File Type To Download In WordPress - True Design

How to Force Any File Type To Download In WordPress

Ever wanted a PDF for example to download rather than open in a tab? Sure there are many WordPress plugins that offer this function, but theres a simple little line of code that you can add to your .htaccess file that will allow instant downloads of any filetype when a link is clicked on your site.

In order to enable this feature you just need to add the below code to your .htaccess file, you can replace pdf with whatever file type suits, .mp3 .mp4 etc.  :

<FilesMatch ".(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

If you would like an easier option of editing your .htaccess file from your WordPress backend, this neat little plugin will allow you to do so -> WP htaccess editor

Even though it hasn’t received an update in 2 years, it still works perfectly fine.

Need help?

If you need some expert help, simply enter your details and we will be glad to assist you.
  • This field is for validation purposes and should be left unchanged.