In readers view, it’s kinda irritating when we try to download the files, instead of downloading it opens in another tab for preview. Then we have to download it from that page. As a blog/site owners, it’s our responsibility to give the best experience to our blog’s readers.
So as usual, I start digging the internet, and find too many WordPress download manager plugins. But every plugin comes with few more JS files, which will make the site to load slower. I don’t want to create another problemĀ by trying to solving one.
Using .htaccess file
By using .htaccess file to force download media files, you are not adding any new additional resources and keeping your site on the same loading speed. Your wordpress .htaccess file will be installed on the same folder with all other wp core files.
You can use cpanel, or filezilla to access the .htaccess file. Once you find the .htaccess file, just open it using any text editors, and then update it with the following code. And save it.
<FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
Note: You can use the same method to force download different type of files, for that all you have to do is just replacing the “pdf” the required file extensions.
That’s all. This setup will force the file to download rather than loading in browser.