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.
- Generates an htaccess file to manage the wp-content/uploads directory where these files are being uploaded
- Updates the htaccess file with canonical tags which are delivered via a header when the attachment is called
- 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
- Allows you to add a canonical url from the media file in the library or when you upload
- 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
How did you guys test this to see if the header response is working properly? I am having trouble finding a reliable tool that will do it.
Hey Will, you can use any of the HTTP headers browser extensions, and you will see that the canonical tag shows up as one of the headers. I use Chrome, and the plugin has a little cloud with a blue outline as the icon.
I am looking for worpdpress plugin for canonical url for PDF files. My site is host on nginx server, and it’s Multi Site.
Thank u in advance.
Thanks Dov, I’ve already replied to your email, but I’ll post an update here as well. The plugin should work fine on any server that relies on .htaccess files. However, since multi-site runs in a single installation of wordpress, the plugin would have to be modified to detect MU and place a new htaccess file in each of the individual sites uploads directory folder. It does not currently do this. I’ll put in on the roadmap, but I don’t suspect I’ll get to it anytime soon. Happy to collaborate if someone wants to pitch in on the plugin.