Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Easily Hide (Noindex) PDF Files in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to hide your PDF files from search engines?

You may be running an online business selling eBooks and want to prevent people from finding the file using search engines. Or you may have sensitive information stored in those PDF documents that shouldn’t be publicly available.

In this article, we will show you how to easily hide (noindex) PDF files in WordPress.

How to Hide (Noindex) PDF Files in WordPress

Why Should You Hide (Noindex) Your PDF Files in WordPress?

PDFs are one of the most popular file formats, and there are many benefits of uploading them on your WordPress website.

PDFs are often used to build an email list. A lot of people convert long tutorials on their blogs into PDFs and then offer them as exclusive content on their websites.

These files are also used to offer exclusive members-only premium content for paying subscribers as part of an online course or membership site.

If you are using PDFs on your website in a similar way, then it is best to hide your files from search engines.

You do not want people to find your PDF files through search results where users would be able to access them without providing you with their email addresses or payments.

You might also have PDFs containing sensitive data that shouldn’t be searchable by the public. Hiding those files using noindex is essential for protection and data security.

That being said, let’s show you how you can easily hide your PDF files from search engines. We will cover different methods, and you can use the quick links below to jump to the one you want to use:

Method 1: How to Hide (Noindex) Your PDF Files Using AIOSEO (Recommended)

The best way to hide your PDF files from search engines is by using the AIOSEO plugin.

All in One SEO (AIOSEO) is the best WordPress SEO plugin on the market that allows you to easily optimize your website for search engines and social media platforms.

This plugin also allows you to edit your robots.txt file, which gives bots instructions about your site.

For this tutorial, you will be adding a bit of code that will tell them to ignore your PDFs.

First, you need to install and activate the AIOSEO plugin. For further instructions, you can see our beginner’s guide on how to install a WordPress plugin.

Next, you will have to set up AIOSEO for your site. If you need help, then you can follow our step-by-step guide on how to set up All in One SEO in WordPress correctly.

Once the plugin is activated, head over to the All in One SEO » Tools page in the WordPress dashboard.

From here, switch to the ‘Robots.txt Editor’ tab and toggle the ‘Enable Custom Robots.txt’ option.

Enable the custom robots txt option

After that, scroll down to where it says ‘User Agent’ and simply add an asterisk (*) to apply the rule to all bots that crawl your site.

Then, select the ‘Disallow’ option in the ‘Rule’ section. Doing this will block all of the user agents from accessing the PDF files. Now, all you have to do is enter a directory path. Simply add /pdf/ in the ‘Directory Path’ field.

Note: If you have saved your PDF directory folder under any other name, then you will have to write that exact PDF directory name in the ‘Directory Path’ field.

Fill in the Rule Builder fields

After that, just scroll down and click on the ‘Save Changes’ button.

Once that’s done, you’ll be able to view your rules in the ‘Robots.txt Preview’ section of the page.

Robots.txt Preview box

Your robots.txt file will now tell search engines to ignore all the PDF files that are present in your PDF directory folder.

If you only want to hide individual PDF files, then you can simply type the name of that PDF in the ‘Directory Path’ field.

An example for a specific PDF you want to hide

For example, as you can see in the image above, entering example-pdf.pdf will prevent that single PDF file from being indexed without affecting others.

You can also add a rule like Disallow: /*.pdf$ to hide all PDFs from search engines, but this will only work when User-agent is set to Googlebot. Not all search engines respect a broad rule like that.

Method 2: How to Hide (Noindex) Your PDF Files Using X-Robots-tag

If, for some reason, the previous method doesn’t work, then you can use the X-Robots-tag to hide your PDF files.

In this method, you will need to manually edit your WordPress site’s .htaccess file and add X-Robots-tag to it.

First, simply connect to your website using any FTP client or by using the file manager app on your WordPress hosting control panel.

Next, locate your .htaccess file, which will be in the same folder as your /wp-content/ and /wp-admin/ folders.

If you cannot find the .htaccess file, then you can follow our tutorial on why you can’t find the .htaccess file to make it visible.

For this tutorial, we will be using FileZilla as an FTP client. Once connected to your site, you will find your .htaccess file in the ‘Remote Site’ section in the right-hand column.

Upon locating the .htaccess file, right-click and open the ‘View/Edit’ option.

view-htaccess-file

This will open the file in a text editor.

If you are using Notepad, here is how it may look after you’ve added the X-Robots-tag.

X-robots-tag in Notepad

If you are using an Apache server, then simply add the following X-Robots-tag in the .htaccess file:

<Files ~ "\.pdf$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>

If you are using the Ngnix server, then add the following code:

location ~* \.pdf$ 
{
add_header X-Robots-Tag "noindex, nofollow";
}

Once you’ve added the X-robots-tag, simply save your file. This will now mark all the .PDF files as noindex/nofollow, which means you’ve succeeded in hiding your PDF files from search engines!

Bonus: How to Protect PDF File Download in WordPress (3 Ways)

The above two methods cover how to hide PDF files from search engines, but if you want to further restrict PDF downloads to members only, require a password or email address to download PDFs, or even collect payments, then you will need one of the following tools:

1. MemberPress

MemberPress is the best WordPress membership plugin in the market. It allows you to restrict PDF file access to registered members only. You can even sell access to PDF files based on different subscription levels the user has.

MemberPress also lets you create and sell online courses, and often, website owners offer premium PDF companion guides with their courses.

Basically, this method will ensure that your PDF files are fully protected, and no one will be able to access your PDF file unless they enter a password and log in.

2. Easy Digital Downloads

Easy Digital Downloads is a popular WordPress eCommerce plugin that helps you sell digital products like PDF files, eBooks, and more.

It comes with maximum file protection features for PDF files, so you can store them in a private cloud, generate unique access links for each member, track download activity, limit the number of times a specific file can be downloaded, and more.

You can accept payments via credit card, PayPal, and others, so you can restrict PDF access by user’s subscription level.

3. OptinMonster

OptinMonster is the best lead generation plugin for WordPress. It helps you get more email subscribers and sales from your website visitors.

A lot of website owners use OptinMonster to require users to enter an email address before giving them access to their PDF files.

This process is called delivering a lead magnet or content upgrade. Once the user enters their email address in OptinMonster, they’re added as a subscriber in your email marketing service or CRM.

After that, they’ll get access to the PDF file in a personalized welcome email.

We hope this article helped you learn how to hide (noindex) your PDF files from search engines. You may also want to see our guide on how to build an email list in WordPress and check out our article on how to stop search engines from crawling a WordPress site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

3 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Kiran says

    In .htaccess file

    Header set X-Robots-Tag “noindex, nofollow”

    is used. Apache server. But when I test, the .pdf URL appears indexable.
    Tried all methods. Still the PDF file is getting indexed in the search engines.

    I read about this code in more than 20 blogposts and forums online. Everyone has told about this option regarding X-Robots-Tag, but no one has told that it is working.
    Can you tell?

    • WPBeginner Support says

      If you have not done so already, please reach out to your hosting provider to ensure there are not rules set on their server that may be conflicting or preventing the change from being accepted for a likely cause.

      Admin

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.