skip down to the 9 comments

RevCanonical 1.2, Customise your link tag plus a little more

I’ve made a few updates to the RevCanonical WordPress plugin I built. These updates add a bit of extra functionality, and also allowed me to tidy up the documentation, so that people know what they’re getting.

First update, is the ability to customise how the link tag is constructed within the head of your page. This is due to the large amount of people who have contacted me, asking why I choose to use rev=canonical and not rel= shorturl, rel=shorturl or rel=short_url etc. As I told them, the reason I chose rev=canonical was to be honest simply because I liked it, and many of my peers were already using this method on their sites. Simple.

So currently with the plugin you get this out of the box:

<link rev="canonical" type="text/html"  href="http://your-domain.com/p12p" />

but you could customise it to be like this:

<link rel="shorturl" href="http://y-doma.in/p12p" />

The reason for this extra customisation is to try and stop people being distracted by the what attribute should I use conversation, and start getting them hosting their own short links they can use. This at least starts solving one problem. When a general consensus, or in deed a standard appears about the attributes, you can simple update and you’re good-to-go.

At the moment the only place you can see the shortened url is either by looking in the source, or using a bookmarklet like the one Simon wrote. I guess I could of injected the url into the admin interface somewhere, but I generally don’t want to see it. The idea is, it’s there for machines to see if they need to, and if I really need to pass it around I’ll just use the bookmarklet.

If you want more flexibility, I have added a of a couple of tags you can use in your templates. These simply let you display the shortened url for a specific post.

# echo the shortened url to the screen
<?php get_revcanonical_shorturl($post_id); ?>
 
# assign the shortened url to a variable
<?php $url = revcanonical_shorturl($post_id); ?>

Oh and finally, just a reminder that this plugin plays well with the TweetMe plugin I wrote that tweets to Twitter.com when you publish a post, and will check to see if you have the RevCanonical plugin installed. If you do, it will use your own shortened url instead of the bit.ly version.

There have been 9 responses to this post.

  1. Juergen Schulze

    Hello,
    first: thanks
    second: doesn’t work with me. I still get an 404 when using one of the generated links

    Bugs: Documentation:
    ID) ?> ===> Echo the shorturl to the screen

    ID) ?> ===> Assign the shorturl to a variable

    The functions you use are indeed
    revcanonical_link and get_revcanonical_link

    But I still can’t use the generated link.
    Did I miss something?

    Juergen

  2. Duncan

    @Juergen, yeah, sorry about this. The new version fixed one persons problem but broke others. I think I’m gonna revert the plugin to the last version. I need someone to run some debug code on their machine so I can see why it’s broken, would you be up for this?

  3. Daniel Matthews

    Yeah, i get the same problem when trying to print the URL to the page, it says i called for an undefined function.

    This is by far the best rev=”canonical” plugin i’ve found, i hope you can find the time to work out the bugs :)

    Also, are there any instructions anywhere of how to set up another domain name? so that, for example, i can show the link as: “http://dan-m.com/pfh” on screen, at the bottom of an article. And it will automatically redirect to the article.

  4. Duncan

    Just to let you know that I am aware of the documentation error and have updated it ready to deploy. Before I do though I’d quite like to fix the 404 problem some people are having. If anyone is willing to run some test code on their sites so I can hunt down the problem, please let me know.

  5. Darren

    Some possible assistance to some people getting 404 pages when trying the canonical link.

    On my server running IIS 6.0 on Win2003 I too was getting 404 errors. However they were not the WordPress 404′s, instead they were the 404 pages supplied by IIS.

    Configuring WP to use custom 404′s (whether they work or not) got past IIS intercepting the redirects and allowed the revcanonical redirect function to be called.

    This may not help with everyone, but if you do see the 404 page issue, try configuring custom 404 pages for your WP theme to see if that is of any help. Google has many references to custom 404 pages for WordPress.

    In my IIS setup this meant changing the 404 error handling in the IIS console from default to /index.php?error=404 then editing the 404.php file in the theme edit section.

  6. Sam J

    rev=canonical has been widely criticised by many, perhaps most notably (and comprehensively) by Mark Nottingham in Counting the ways that rev=”canonical” hurts the Web.

    Perhaps you would consider contributing to/merging with the shortlink WordPress plugin now that WordPress.com has rolled out this feature?

    Sam

  7. Tom

    Duncan,

    GREAT plugin … too many of the short url plugins add a bunch of stuff we don’t need when all we want is a short url.

    I do have one problem. Once installed, the plugin broke my date archives. For instance, when someone called up http://www.mysite.com/2009/11/12/ (which should show the posts for Nov. 12, 2009) it redirects to the About page.

    Any suggestions?

  8. Duncan

    @tom, Thanks for your comment. I posted a new version of the plugin this morning as I found a fix for your problem. I’m don’t I’ll ever fix all url/setup combinations out there but there you go. Sorry for the delay, but this plugin is not high on my maintain list at the moment.

  9. Tom

    Duncan,

    Thanks for the update! Works great!


back to the top