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.
Seems like a sweet plugin, Justin! Definitely gonna have to try it out. Thanks for sharing 🙂
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.
Hmmm… Awesome, this makes blogging easier. Thanks for your time of writing this!
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.
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.
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.
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.
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 🙂
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 🙂
Pretty useful – no more broken links due to changed permalink structure/domain
Actually I like the idea.
But how should I get a post ID?
only using phpMyAdmin?
I sure hope this helps Justin. I have been having some permalink problems with one of my blogs. I changed the structure to custom and then added /%title%/ which works for my pages, but not my blog posts. I am going to download this plugin and see if I can get it corrected.
I ended up figuring out my problem on my own, but in case anyone has this problem and reads this. You need to change the custom permalink to /%postname%/ and this will work for all posts, pages, and forum permalinks.
I’m new into blogging and I’m actually looking for instruction on how to activate permalink. I’m quite confuse ‘coz I’m just a novice blogger.
I wonder how what you mean by “links are protected with this method”, has this something to do with SEO? or just keeping the link structure intact?
“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.”
Appreciate your response.
Thanks.
I keep having a related problem with Permalinks. I try to use Custom to make a /%postname%/ with no success. It keeps asking to edit .htaccess. Any suggestions?
I was using your plugin and it was working and now it is not for some reason. I am using the latest version of wordpress is this plugin compatible?
What I would like, and surprisingly have never found, is a javascript type popup link in admin that would list all my posts and pages with their respective ids and allow me to insert them into the post with the click of a mouse. That way I wouldn’t have to go hunt down the page id# to then insert it into my posts. I like to link between posts a lot and haven’t found a quick easy way to list my posts. I guess I’ll get used to it though
Thanks, it is a great plugin and working fine
Thanks, I too believe that this should be a fundamental feature of wordpress. I appreciate you taking the time to help those of us who only know a few html tags, but need the features. I downloaded and installed as per your instructions easily, and added the following to the HTML page: [permalink href=”100″]Name of Post[/permalink] link, where 100 is the post number. It all worked a treat and I recommend others try it too.
Works like a charm and I just upgraded to WordPress 2.8
I have a disease page and in the list of differential diagnosis, I have diseases that looks similar to the disease in the current page. I am now linking to the pages of those diseases using your plug-in.
For those who don’t know how to get the Page ID. Just go to pages under your Admin panel. Hover your cursor on the name of the page and in the status bar you will see your blog url plus some code at the end.
Ex:
/wp-admin/page.php?action=edit&post=713
so here the Page ID is 713. Hope that help some folks out there.
Brilliant!
I’ve never written a plugin before, or even looked at the source. Looking at yours, I see it’s not that hard. I was going to ask for a feature, but I figured out how to add it myself. Maybe you can add it to yours.
I wanted the ability to specify a target (like _blank) to open up the link in another tab/window. Most of the links on my website do that, so the post doesn’t go away. So I added “‘target’ => false,” to the extract call and “if($target) $link .= ‘ target=”‘ . $target . ‘”‘;” after the title handling.
I had thoughts of being clevererer and trying to find a way to handle arbitrary attributes to add to the href link, but it’s 2:30am, and I have a cubicle to bang my head against tomorrow morning.
pretty useful at the beginning, but later we get so used to it that we can type the entire “code” without any effort lol
Is there an easy way to link to an anchor on a page with one of these permalink short tags? Something like [permalink href=”6″#news] ?
Thanks man, this is just what I needed. Great, simple plugin that works like it’s advertised.
Great plugin!
Thanks a lot for this saved me a lot of time when moving a lot of content from a dev server to production
Tried to install this plugin and was told by Wordpress:
Unpacking the package.
Incompatible archive PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
What to do?
Just installed it. This is exactly what I have been looking for. Thanks.
i installed it in 3.05 and i got a php error . please help . thank you !
I have the same question as “Kim Flournoy”, i like to use “named anchors”.
For example i have one page with the next code:
[permalink href=”352#TIPS”]link to second page”[/permalink]
But this does not work.
The plugin does not receive the “#tips” part (with the “get_permalink” function, so i can’t change the code.
Any thoughts Justin?
Thanks! 🙂
Nice plugin. great work
Can I Link to Tag instead of linking to Post ?