I recently decided to abandon YOURLS as my shortlink solution, opting instead to handle short URLs entirely within WordPress. This choice is not a reflection on YOURLS–it’s still a great product–but rather was borne from my use case for shortlinks; I concluded that, since I only used them in conjunction with WordPress, an external shortlink service was excessive.
While WordPress has provided a native shortlinks feature since the 3.0 release, it uses query strings rather than pretty permalinks. This means that the shortlink for this post would be http://ethitter.com/?p=6360. It’s not the prettiest URL, nor will many systems cache that request; as a result, each shortlink that’s followed would load all of WordPress just to perform a redirect to the post’s full URL. Unsatisfied with Core’s handling but also unwilling to retain YOURLS, I wrote a small WordPress plugin to address my needs.
ETH Simple Shortlinks converts query-based shortlinks to versions that use WordPress’s rewrites system. When active, http://ethitter.com/?p=6360 becomes http://ethitter.com/p/6360/, though the former URL will still resolve as expected.
The plugin overrides the shortlink output WordPress generates, ensuring that the new format is used wherever a short URL is expected. For convenience, the shortlink is also exposed in content lists in the WordPress admin.
By default, the plugin supports posts and pages that are either published or scheduled. Filters allow other post types and statuses to be included.
The plugin is available from the WordPress.org repository: https://wordpress.org/plugins/eth-simple-shortlinks/. Development is on GitHub: https://github.com/ethitter/eth-simple-shortlinks.
That’s pretty cool! And wow, I think it’s the second plugin I ever wrote, haven’t updated it in six years. I made a video too, good times 🙂
Thanks!
Wow, everything old is new again! 😆 I even checked the repo for duplicates before submitting mine, but I only searched, I didn’t check tags.
I guess Konstantin was a couple years ahead of me. I think I have some changes on Github that never made it to the repo.
I’ve occasionally thought of adding a ‘redirect’ post type that would just redirect to external URLs and maybe support custom slugs. It would probably be kind of hard to do without adding a prefix like you have. I’m sure there are already edge cases in my plugin that will trigger a redirect when you don’t want it to.
Oh fun, I’m clearly in good company with this plugin.
If I find I need ad-hoc short URLs, I’ll probably add another site to my network, map a short domain to it, and use my External Permalinks Redux plugin along with this plugin. Hopefully I don’t need to, though. 😀
The prefix is definitely a bit of a cheat, but I’m hoping that borrowing Core’s query var for that will minimize conflicts. That said, I have just realized that the rewrite rule doesn’t consider if the permalink structure has a prefix, which I’ll need to correct.
Something I cooked up most of the way a bit ago, but never actually got around to submitting to the plugins repository —
https://github.com/georgestephanis/short/blob/master/short.php
Kinda like YOURLS, but in WordPress as a CPT instead.
Seems you should team up with Josh and release this.