?>

Canonical Attachments in WordPress

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


Comments


  1. 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.

    Reply

  2. 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.

    Reply

  3. Hello Jacob
    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.
    Dov

    Reply

  4. 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.

    Reply

Trackbacks

    Leave a Reply

    Get Started

    800-650-0820

    Hive Digital can help you get the most out of your website. Simply fill out this form, and we'll get back to you with a free quote. No risk, no obligation.

    Hive Digital respects your privacy. We will never spam you or sell your information to any third party. Privacy Policy


    Subscribe via Email

    Subscribe to receive notifications of new posts by email.

    Follow Us on Twitter


    Get Started

    800-650-0820

    Hive Digital can help you get the most out of your website. Simply fill out this form, and we'll get back to you with a free quote. No risk, no obligation.

    Hive Digital respects your privacy. We will never spam you or sell your information to any third party. Privacy Policy

    [X] Close