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.

10 Responses to “Get Permalink WordPress plugin”

  1. Seems like a sweet plugin, Justin! Definitely gonna have to try it out. Thanks for sharing :)

  2. Michael
    I think it could be useful for a lot of people. I figured it wouldn’t take long to write, so I just dived right in.

  3. Hmmm… Awesome, this makes blogging easier. Thanks for your time of writing this!

  4. Great idea! Does the plugin permanently write the code into the post, or does the [permalink] shortcode stay and get processed on the fly when a post is displayed? I’m asking because I’ve seen some plugins that do similar things, but if the plugin is ever disabled, the user is stuck with shortcode in their posts.

  5. J Mehmett
    No problem. It’ll definitely take away from permalink problems when linking within posts.

    Dan
    If the plugin wrote the code permanently into the post, you’d be stuck in the same situation — broken URLs when changing a page/post slug. So, it has to be done “on the fly.”

    As you’ve mentioned, there’s the problems of shortcodes being left in the post if the plugin is deactivated. It’s my biggest gripe with the shortcode API, and one reason I won’t use this plugin myself.

    Of course, if I ever deactivated my PHP plugin, then I’d have PHP code in a lot of places that doesn’t work.

    So, it’s something you should think about using for the long haul if you decide to use it. I’ve actually got a post planned on why the shortcode API can be bad for your blog for the same reasons you’ve stated.

    I personally prefer not changing post/page slugs, but sometimes, I’m in a situation where I change some pages around on this site. But, since it’s a personal blog, it’s not that big of a deal to me.

  6. This is an interesting idea, but I’m not sure how much utility it has. As far as I understand, WordPress has automatic 301 forwarding in cases where a post permalink has changed since it was originally published.

    I suppose this might have SEO utility, but I don’t understand enough about either forwarding or SEO to be able to say.

  7. david
    It’s definitely not for everyone, especially with the automatic 301 forwarding (which may or may not work from my experience).

    I figured I’d just throw the plugin together to help out someone over at the WordPress Ideas Forum because it literally took me less than 15 minutes to write and test it.

    I wouldn’t recommend it to anyone that knows their way around WordPress anyway.

  8. Justin,

    Great idea and great plugin.

    I should admin that you should be a good coder because you got the plugin in just 15 mnts :)

  9. Adding one more line. just now checked the plugin code. it is really simple and easy to implement. but the difference between you and me is you got the idea to create the plugin :)

  10. Pretty useful - no more broken links due to changed permalink structure/domain

Leave a Reply