While working on a client project, I realized they had a significant number of PDF files that they had uploaded into wordpress, and this was creating some issues in organic search results. Most notably, many PDFs were outranking or replacing their post/page counterparts, and more importantly, the PDFs did not have CTA’s or analytics tracking. As such, we lost the ability to convert the visitor from the PDF, and our only measure of traffic was via what is available in search console when looking at urls containing .pdfs and their performance in search results.

Download the Canonical Attachments WordPress Plugin

For this client, they would typically write a blog post to support a news item or recent case-study, and then upload/attached the corresponding PDF file. To address the issue above, I wanted to be able to quickly add a canonical tag to the PDF, Powerpoint, or doc file pointing to the post or page that it was attached to. In searching, I was unable to find any existing solutions for this problem, so I built out a wordpress plugin that addresses the issue. I’m in the process of submitting this plugin to the wordpress repository, and will update the post when it goes live.

The challenge:  Files cannot have a standard canonical tag added in the <head> and instead the canonical tag has to be added via an http header when the file is requested from the server.  In order to accomplish this, we need to have an htaccess file listening for a request to that file, and then sending the header.

The plugin:

  1. Generates an htaccess file to manage the wp-content/uploads directory where these files are being uploaded
  2. Updates the htaccess file with canonical tags which are delivered via a header when the attachment is called
  3. Creates a dashboard where you can easily attach a file to its parent post (one at a time or in bulk) or manually add/remove a canonical tag for a file
  4. Allows you to add a canonical url from the media file in the library or when you upload
  5. Creates a dashboard to edit the .htacess file directly for the uploads directory in case there are additional files in the directory that were uploaded outside of wordpress (e.g. during a site migration)

Expected outcome:  PDF files and other attachments will be replaced in search results with the post or page counterparts, and we will be able to measure the traffic to those pages and provide calls to action for downloading the file, submitting contact forms, etc.

UPDATE:  The plugin has now been included in the wordpress repository.  You can view here – Canonical Attachments WordPress Plugin