Browsing the archives for the Wordpress tag

Canonical URLs in WordPress

Like any good obsessive-compulsive blogger, I frequently pour over my web site statistics looking for interesting stuff. One thing that caught my eye is that search results coming in from Google tends to link to threaded comment pages for entries.

For example, I’d get hits to /blog/2009/03/05/entry-slug/comment-page-1/, which is an URL that’s pretty hard to actually find on the page — it’s only used for permanent links to entry comments, with an anchor to the comment ID tacked on, like this.

What I’d prefer to see is incoming hits to the actual blog entry URL /blog/2009/03/05/entry-slug/ in this case. Luckily, there’s a smart and simple solution — canonical URLs. The Google Webmaster blog explains it nicely with examples.

So I simply add a canonical tag referencing the preferred URL in each page. Now, it’s just the preferred URL on my side — this is just a hint to search engines that tells them that this page is a duplicate, and that I’d prefer them to let results point to one particular page of these duplicates. In 99% of the cases it will be respected, though.

The actual code is just a few lines. Add this in header.php of your theme, somewhere in the head:


<?php if (is_singular()) { ?>
<link rel="canonical" href="<?php the_permalink() ?>" />
<?php } ?>

is_singular is a function that returns true if any of is_single(), is_page() or is_attachment return true — in other words, if you’re currently visiting a single entry, a page or an attachment.

With this, each entry sub-page of comments has the main entry URL as their canonical URL. Now to wait a few days and see when the search engines1 pick up the change.

1 And by “search engines” I mean “Google.”

No Comments

Bookmarks for 26/01 through 02/02

These are links I found interesting for 26/01 through 30/01:

  • GlimmerBlocker — Ad blocker for Safari implemented as a non-intrusive proxy.
  • Noscope | Journal | Extra Image Tags Plugin — This is a very minimalistic Wordpress plugin, which finds all images you insert into your posts, and wrap them in extra divs, so you can style the hell out of them.
  • The $300 Million Button — “It's hard to imagine a form that could be simpler: two fields, two buttons, and one link. Yet, it turns out this form was preventing customers from purchasing products from a major e-commerce site, to the tune of $300,000,000 a year. What was even worse: the designers of the site had no clue there was even a problem.”
  • Cops Talk Funny — “From recruits in academies to senior officers and command staff, you talk funny when you take the stand. Is it in the water at the academies; is there a secret society where you're taught this special language?”
  • Videogames outsell DVD and Blu-ray in 2008 — Retail sales of videogames overtook that of DVD and Blu-ray for the first time, as sales of packaged media grew 6 per cent worldwide to hit USD 61 billion in 2008, according to Media Control GfK International.
No Comments

Flickr Album

PICT2171

I just installed the Flickr Photo Album plugin for Wordpress, and I’m pretty impressed so far.

I used to post Flickr images by cut-n-pasting a text snippet I had stored as a Wordpress note and replacing the relevant links with those of the photo I wanted to post. It works, but it’s kinda clunky and slow to do. With Flickr Photo Album you get a bar on the Write Post screen displaying your latest Flickr images, inserting the proper HTML with just two clicks — one to select the photo, another to select the size of the image you want to post. Perfect!

But wait, there’s more! You also get an integrated Flickr photo album (hence the name) — mine is located here. It looks kinda boring, but I’ll fiddle with the design of it later.

Definitely going to support this plugin in Kestrel.

In the other news, allergy season has started. Yay.

No Comments

A New Hope

It’s been a long time, but I’ve started fiddling a bit with web design again. While I do like K2, I prefer to make my own design. And K2 was always meant to be temporary here until I found my long lost design groove again. And I think I spotted it out in the gutter, drunk out of its mind. It’s in rehab now.

I’ve started work on a Wordpress theme tentatively called Kestrel. I’m writing the basic layout now with the theme development page readily available in another tab.

I do admit that it feels a bit messy to use pure PHP instead of a template language like Movable Type uses, but I’ll manage.

Since doing live editing gets messy I’ve set up a local web server hosted on my file server. lighttpd as web server, PHP and MySQL.

lighttpd is very nice for local development — it doesn’t include the entire kitchen sink like Apache does. It took a bit of work to get it going the way I wanted, though. For a while it decided to send me the PHP source code instead of passing it on to PHP – but only when I accessed a PHP file from my workstation. When viewed locally it worked properly.

No Comments

SNAFU

The front page was b0rked for a couple of hours. I still had Movable Type installed, and it looks like someone managed to send a trackback (I had deleted mt-comments.cgi to prevent spam, since I don’t even use MT any more), which caused the front page to be overwritten by MT.

I took this as a sign that it was time to upgrade to Wordpress 1.5. So I did. All is well again.

Later: Surprise surprise, it was trackback spam.

No Comments

200:1

Since I switched from Movable Type to Wordpress, I’ve had one (1) legit comment.

And 200 attempted spam comments that Spam Karma shot on sight.

Addendum: 11 days later, and I’ve passed 900.

1 Comment