Justin Tadlock

Get Permalink WordPress plugin

I was surfing the WordPress Ideas forum as I usually do every other day or so when I came across an interesting idea for a plugin.

The idea was for an easy way to link to other posts within the same blog without those links ever being broken (even if you change the page/post slug in the future).

This is easy if you have a PHP plugin installed. You just use the get_permalink() function. I suppose not all folks want to mess around with PHP though.

Anyway, 15 minutes later, I had the plugin running and a few tests done.

Download

As usual, unzip the get-permalink file. Then, upload it to your /wp-content/plugins directory. Activate it from your WordPress dashboard.

How to use this plugin

The basic syntax is the same as normal hyperlinks, so there shouldn’t be any confusion about how it works.

If you’re just looking for a simple link to a post or page, just add this when writing a post (the 100 is the ID of the post or page):

[permalink href="100"]Hello world![/permalink]

The resulting output would be this:

<a href="http://yoursite.com/link-to-post" title="Title of your post" rel="bookmark">Hello World!</a>

Well, there’s more you can do, such as define the title, rel, and class of the link. Something like this might suit your fancy:

[permalink href="100" title="Super cool post title" rel="nofollow" class="red-class"]Cool post[/permalink]

How about an image?

[permalink href="100" class="alignleft"]<img src="image.jpg" alt="Example image" />[/permalink]

Why would you need such a plugin?

Well, it’s pretty useless to me since I always keep a PHP plugin installed and can easily use a WP function for this. Plus, I don’t plan on changing too many permalinks anyway.

You might say, “Why not just link directly to the post’s URL?” That’s fine, but if you ever change your permalink structure or change a page/post slug, then you’re in for some trouble. You’ll have broken links.

What happens if you ever decide to change your domain name but want to keep the same posts? Well, your links are protected with this method.

The post/page ID never changes though. So, if you’re linking directly to the ID, your links will always be safe.

It’s not a plugin for everybody, but some might find it useful.

I don’t think there should be any major problems, but I did write this pretty quickly. So, let me know if you run into any trouble, and I’ll fix any issues.