A client who runs an industry news site on a WordPress blog requested a print formatting solution that would allow them to serve custom ads for the print-friendly pages.
My starting point, WP-Print
Looking to avoid reinvention of the wheel, I found WP-Print, a plugin that would save development time and money. It was a great starting point for this project because it comes with a number of features and options for non-technical users to control via the WordPress admin interface.
There were, however, two customizations I needed to make. One to preserve SEO integrity via canonical linking (which is the topic of this article) and a second modification to insert the ad code into the print-formatted content. The latter was a requirement from my client and was the reason why I couldn’t just make a print-specific CSS file for the main theme itself.
Canonical links, why should I care?
With the print version, essentially duplicating an article’s content on a separate URL, providing a canonical link to the original content is a good practice to prevent your content from receiving ranking penalties by search engines. For more on that issue, see Matt Cutts talk about it in a video presentation over at Google. Unfortunately, the WP-Print plugin (as of version X) does not provide for a canonical link within the output code. Joost de Valk reviewed WP-Print on his site and also noted this issue and gave the plugin a lower rating on his scale as a result. Fortunately, it’s relatively easy to fix this problem via the insertion of just one line of code in the print template provided with the plugin.
How to add canonical links in WP-Print output to browsers:
- Copythe following files from the ../plugins/wp-print/ folder:
- And paste them into your current theme’s folder. You’ll be working with these new files from now on, leaving clean, original copies of them in the plugin folder.
- Add the following line of code within the
headsection of the print-posts.php file:
<link rel="canonical" href="< ?php the_permalink(); ?>"/>
- Save it, and test it out!
The code simply calls the content’s permalink as stored in the WordPress database and will point search engines to the original page so that duplicate content isn’t indexed. That way, Google, Yahoo, Bing, and others will not penalize you for spamming their indexes.
You can make further customizations to the files within your theme’s folder without breaking the plugin and without risk of losing your customizations if the plugin is updated/upgraded. I took some time to clean up the syntax a bit, making changes in the code to have all ID’s and classes in lowercase format as well as other tweaks to make the output more closely match the design of my client’s site.
I’ll be contacting the plugin author, Lester Chan, with this fix. Hopefully, it will be included in a future update. UPDATE! I heard back from Lester, and he’s committed my suggestion for the canonical link code into the plugin, and it will be live with the next release. Check it out here: http://plugins.trac.wordpress.org/changeset/445061.
I hope this post helps make things a little easier for folks who need this type of functionality. If you have any questions about this or need to point out any problems, just leave me a comment here to discuss.