Skip to main content
Easy Digital Downloads Blog
WordPress Tutorials, Tips, and Resources to Help Grow Your Business
How to Force WordPress Files to Download (Not Open in Browser)

When selling digital assets and downloads, some store owners set product links to open within the user’s browser. But there may be times when you want to force WordPress files to download instead.

This is possible. Easy Digital Downloads lets you configure your WordPress website so files download rather than open in a new tab. There are many reasons this can be beneficial.

πŸ”Ž In this post, we’ll cover:

Why Force WordPress Files to Download?

There are a few reasons you may want to force WordPress files to download instead of opening in a browser. One is if you’re offering large files for download. Forcing file downloads can help avoid potential issues with users’ browsers timing out while loading files.

Also, forcing files to download means customers can access them anytime from anywhere. For example, they could use them even while offline.

Perhaps you want to offer a file that’s not traditionally associated with a particular program (like a .txt file). If you force WordPress files to download, users can open them with the program of their choice.

This functionality can come in handy when you have multiple versions available. You can ensure customers always have the most up-to-date version. Plus, forced downloads increase file security because they’re not cached by the user’s browser.

Learning how to force WordPress files to download is beneficial if you sell digital products, such as eBooks or PDF files. Forced downloads deliver the product(s) directly to your customers. This eliminates the need to manually send the downloadable files to your customers after every sale.

How to Force WordPress Files to Download (2 Methods)

There are two main ways that you can force WordPress files to download. The fastest, easiest, and safest option is to use a plugin like Easy Digital Downloads.

The second option is to manually force files to download. This isn’t necessarily a beginner-friendly solution. It involves editing your site’s files and working with code. So if that’s not something you’re comfortable with, we recommend sticking with the first method.

In the following tutorials, we’ll walk you through both options, starting with EDD.

1. Force WordPress Files to Download With EDD

If you’re selling digital products through WordPress, Easy Digital Downloads (EDD) is an ideal solution.

The EDD and WordPress logos.

The popular WooCommerce alternative is easy to set up and use. The WordPress plugin has many features and add-ons to make the selling process as smooth as possible.

You can also choose from multiple pricing options. After you complete your purchase, you can visit your account dashboard. Then you can navigate to the File Downloads tab and select Get Easy Digital Downloads:

The File Downloads screen in EDD.

After you install the Easy Digital Downloads plugin, you can configure the file download settings. Go to Downloads Β» Settings Β» Misc Β» File Downloads:

The File Downloads menu item in Easy Digital Downloads.

There are two ways that you can use Easy Digital Downloads to deliver files to customers: Redirect and Forced. You can find these options under Download Method:

The download method options in EDD where you can force WordPress files to download.

Forced is the default method. Without getting too technical, with this option, EDD uses PHP and separates the file into smaller pieces. Then it delivers them to the browser without redirecting users to the actual file.

In other words, the Forced setting forces WordPress files to download when a user clicks on the download link.

Using Redirect and Amazon S3/Dropbox Delivery Method

With the Redirect delivery method, the plugin tells the browser where the file is located. Then it begins to download it directly from the server. The file downloads and opens within the browser.

This is ideal if you have large files hosted on a third-party platform, such as Google Drive, Amazon S3,Β orΒ Dropbox.

EDD offers extensions that let you integrate with both Amazon and Dropbox to easily access and upload files. You can install them by going to Downloads Β» Extensions Β» All from your WordPress site dashboard.

Next, select Download Now under the extension you want to use:

The File Store for Dropbox extension download now option.

When the zip file finishes downloading, you can add it to your site (Plugins Β» Add New Β» Upload Plugin).

To learn more, feel free to check out:

2. Manually Force Files to Download in WordPress

Another way to force WordPress files to download is to manually edit your .htaccess file. This approach requires you to edit your site’s HTML code. To get started, connect to your site using a File Transfer Protocol (FTP) client or your web hosting provider’s File Manager.

Navigate to the root directory, followed by wp-content/uploads (usually under wp-admin):

The SiteGround File Manager.

Locate the .htaccess file. Then right-click on the filename to open/edit it:

The option to use a File Manager to edit the .htaccess file.

Within the .htaccess file, copy and paste the following code:

# Force file download
<FilesMatch "\.(jpg|jpeg|png|gif|mp3|mp4|mpg|mpeg|avi|txt)$">
	ForceType application/octet-stream
	Header set Content-Disposition attachment
</FilesMatch>
# END

When you’re done, save the file. Now whenever a user clicks on a link for any of the media file types listed in the code snippet, the content will automatically download.

Another option is adding a <a href> tag to downloadable files. For instance:

<a href="examplefile.pdf" download>Click to Download</a>

But this can be time-consuming and easy to forget to do (especially when you have a lot of files).

Force Files to Download in WordPress

If you want to improve the customer experience on your eCommerce website, you can force WordPress files to download. An alternative to having files open within the browser, this method can help boost file security and let users access the download anytime from anywhere.

Download Easy Digital Downloads today to get started with this built-in functionality. Ready for another strategy for managing WordPress file downloads? Learn How to Limit File Downloads to Logged In Users. πŸ”’

Finally, be sure to subscribe to our newsletter and follow us on Facebook or Twitter for more WordPress resources!

Using WordPress and want to get Easy Digital Downloads for free?

Enter the URL to your WordPress website to install.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. We only recommend products that we believe will add value to our readers.

8 comments

  1. Casey Cavanagh

    Thank you for your method with the htaccess file, it saved me a lot of time to force download for my docx files!

    1. Casey Cavanagh
      1. Casey Cavanagh

        Will I have to add the lines to the .htaccess whenever there is an update of my theme ?

  2. Casey Cavanagh

    Please, this trick didd’nt work, because i use cyberpanel, i have tried this and it does not work.

    1. Casey Cavanagh
  3. Casey Cavanagh
  4. Casey Cavanagh

    Many thanks to easydigitaldownloads for providing this code of .htaccess.
    # Force file download

    ForceType application/octet-stream
    Header set Content-Disposition attachment

    # END
    This is working on my website bgmtub.com
    I am very bothered to know how to download media files on wordpress website

    1. Casey Cavanagh

Leave a Reply

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