When it comes to taking your business to the web, people from around the world prefer using WordPress to establish their online presence. Carrying out your business online means that there will be several occasions when you need to share certain files with your clients or teammates. However, there will be times when you might want to restrict the access or the visibility of the file.

Wondering about the solution?

You can password-protect your WordPress files. Put simply, you can assign passwords to only those users whom you want to share your website resources. In this post, I will share with you how you can protect your files with passwords and allow only members to access them. But, before that let us first talk about a few benefits that you'll get by making your files password-protected.

Benefits of Making Your WordPress Files Password-enabled

Attracts Traffic to Website: We all run promotional campaigns in a bid to drive traffic. In fact, most of us, even pay a hefty amount for the same. But, what if you could bring traffic to your website without paying even a single dime. You heard it right! Making your resources password-enabled that only gets downloaded by registered members of your website can work as a great marketing strategy.

Wondering how?

Keeping the data hidden from users excites them to know what exactly it contains. And so, chances are that they will become premium members of your website to access the hidden data.

Keep a Track of Users: As users will log in to your admin panel to download the files, you will come to know the number of users in total who are interested in accessing your website resources. This will help you keep a track of the number of users getting logged in into your wp-admin, which also gives an idea of the traffic you're receiving on your website.

How to Make WordPress Files Password-enabled?

You can find WordPress plugins that allow only password-based downloads, however, they might not be able to meet your exact needs. However, just writing a simple code can help you meet your objective in a relatively easy manner.

Here I'm writing a simple php code snippet that will ensure that your media files can be downloaded only be logged-in users. The below code should be included in your theme's functions file:

Click links to download Media file

<?php
if ( is_user_logged_in() ) { ?>
<p><strong>Click links to download Media file</strong></p>
<a href="http://localhost/wordpresstheme/wp-content/uploads/2014/12/gr.png">Download Image</a>
<a href="http://localhost/wordpresstheme/wp-content/uploads/2014/12/gr.png">Download Image</a>
<a href="http://localhost/wordpresstheme/wp-content/uploads/2014/12/gr.png">Download Image</a>
<a href="http://localhost/wordpresstheme/wp-content/uploads/2014/12/gr.png">Download Image</a>
<?php
}
else {
?>

<p>Some content are password protected if you want top see click the below link<br/>

<a href="<?php echo site_url(); ?>/wp-admin">See content</a>

<?php } ?>
For non-tech savvy people, trying to make even minor tweaks to a WordPress theme's file can be an absolute nightmare. And so, they might find the above code snippet a little hard to digest! But, the code isn't complex at all.

Let us understand how does the code works, by breaking it down:

In the conditional tag <?php if ( is_user_logged_in() ) { ?>, is_user_logged_in() function is WordPress' default function that check if the user is logged-in WordPress admin panel or not. The logged-in users will be able to download the image files. So, the tag will be 'True' only when the user is logged in and 'False' if not.

Protect Media Files: How to allow password based downloads only?

If the condition tag is false, then the else part of the code will be executed. Here users will see a non-login screen that looks something like the below screenshot:

Protect Media Files: How to allow password based downloads only?

As you can see in the above screenshot, there is a link on 'See Files'. When a user clicks on the hyperlink, they'll be directed to the wp-admin login page.

You can follow a similar approach to protect any WordPress files to be accessed by any regular website visitor. For instance, you can even make your users constantly download PDFs through your WordPress admin panel that needs password protection.

Wrapping Up!

There are tons of amazing things that you could do with WordPress. Protecting your files, by allowing only premium members to download them is one such great functionality you can enjoy. However, this will benefit you not only as a marketing strategy but will also allow restricted file access to more authenticated users, in order to make the content exclusive and available to those users only with complete safety.

Do you want to know how you can share only some specific media files with your WordPress users? Hopefully reading this tutorial will provide you with some resourceful insights.