How to noindex PDF files in WordPress

To noindex PDF files in WordPress, send an X-Robots-Tag: noindex HTTP header with every .pdf response. A PDF has no HTML head, so a robots meta tag is impossible, and SEO plugins cannot add one because the web server delivers files in /wp-content/uploads/ without loading WordPress.

Do this for PDFs that duplicate a page, such as a printable version of an article, or for files that were never meant to be found through search, such as internal price lists. Leave PDFs indexable when they are the content, for example a manual people search for by name.

Step by step

1. Decide which PDFs to cover

You have three scopes, from broad to narrow: every PDF on the site, PDFs in one folder, or a few named files. WordPress stores uploads in year and month folders (/wp-content/uploads/2026/11/), so a single folder rarely matches a meaningful group. If only some PDFs should be hidden, give them a shared file name prefix such as internal- before uploading and match on that.

2. Add the header on Apache or LiteSpeed

Edit the .htaccess file in your site root and add this above the # BEGIN WordPress line, so WordPress never overwrites it:

apache
<IfModule mod_headers.c>
  <FilesMatch "\.pdf$">
    Header set X-Robots-Tag "noindex"
  </FilesMatch>
</IfModule>

To match only prefixed files, change the pattern to "^internal-.*\.pdf$". The rule needs mod_headers, which most hosts enable. LiteSpeed reads the same syntax.

3. Add the header on nginx

nginx ignores .htaccess. Add a location block inside the server block of your site config and reload nginx:

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

One nginx detail: add_header lines in a location replace any inherited from the server block, so repeat other headers you rely on, such as HSTS, inside this block. On managed hosts without config access, look for a "custom headers" or "header rules" panel, or ask support to add the rule.

4. Or set it at the CDN

If files are served through a CDN, you can add the header there with a response header rule that matches URLs ending in .pdf. This also covers PDFs offloaded to object storage, which never touch your web server.

5. Verify with curl

Request a PDF's headers:

bash
curl -sI https://example.com/wp-content/uploads/2026/11/price-list.pdf | grep -i x-robots-tag

You should see x-robots-tag: noindex. No output means the rule is not matching: check the file extension case, whether a CDN is serving a cached copy without the header, and on Apache whether mod_headers is loaded. In Search Console, URL Inspection on the PDF address shows Indexing allowed? No: 'noindex' detected in 'X-Robots-Tag' http header after a live test.

6. Keep the files crawlable

Do not also block the PDFs in robots.txt. A crawler has to fetch the file to receive the header. If /wp-content/uploads/ or *.pdf is disallowed, Google never sees the noindex, and a PDF that is linked from elsewhere can stay listed by its URL alone.

Removing a PDF that is already indexed

The header works on the next crawl of that file, and PDFs are often recrawled slowly. For something urgent, use the Removals tool in Search Console to hide the URL for about six months while the header takes effect. If the file should not be public at all, delete it from the Media Library, or move it behind a login. Noindex does not stop anyone with the link from opening it.

When a canonical header is the better fit

If a PDF is a copy of an HTML page and you would like the page to rank instead, you can send a Link header from the PDF that names the page as canonical: Link: <https://example.com/guide/>; rel="canonical". Google documents this header for non-HTML files. It is a hint, where noindex is a directive, so use noindex when the file must stay out.

What Hydrogen SEO does here

The plugin's robots controls apply to pages WordPress renders, and file requests bypass WordPress, so the header has to come from the server or CDN. What the plugin does handle is the page WordPress creates for each upload: Redirect Attachment Pages under Hydrogen SEO → General → Permalinks sends those to the parent post or the file. See redirect attachment pages.

Common questions

Can I add a noindex meta tag to a PDF?

No. Meta tags live in HTML. For PDFs, images and other files, the X-Robots-Tag HTTP header carries the same directives.

Will robots.txt keep PDFs out of Google?

It stops crawling, not indexing. A blocked PDF that other pages link to can still appear as a bare URL. Use the noindex header and leave the file crawlable.

Does this work for Word and Excel files too?

Yes. Extend the pattern, for example `"\.(pdf|docx?|xlsx?)$"` on Apache, and the header is sent for those types as well.