How to Force File Download in WordPress

Last Updated on November 14, 2020 by Kings

WordPress is one of the best CMS for file and content uploads and downloads, because of it’s easy use and stability a lot of content creators from different segment make use of wordpress. If you ever wanted an onclick download of file on your wordpress site instead of opening on a new tab, keep reading as i will show you a very simple way to do that.

How To Onclick Download Files on WordPress


Below is a guide on how to enable instant downloads of files in your wordpress site instead of displaying or playing them on a new tab.
Force file download in wordpress

How To Force File Download in WordPress via Htaccess

In other to enable direct file downloads, add the below line of code below in the end of your .htaccess file

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

You can replace mp4 with whatever file type you want it to download and if you want to add force download to multiple files then add the below code to your htaccess file

For easier access to editing htaccess you can make use of wordpress Htaccess Editor

I will also update this post on another method to force files to download (not open in browser) soon.