Right now my shortlink structure looks something like this:
example.com/?p=451
I would prefer it to look more like this:
example.com/abc123
Any ideas how I can alter the code to do just this?
|
Right now my shortlink structure looks something like this: example.com/?p=451 I would prefer it to look more like this: example.com/abc123 Any ideas how I can alter the code to do just this? |
|||||||||
|
|
Okay, so, as mentioned in my comment to you: altering core files is not a good idea. But here is a plugin solution. First we're going to create our own rewrite rules that rewrite
The Then we can hook into template redirect and see if our query variable is there. If it is, we'll try and get a permalink out of it. If that fails, we'll throw a 404 error. Otherwise, we'll use `wp_redirect' to send folks to the actual post.
Finally, we hook into
As a plugin: https://gist.github.com/1179555 |
|||||||||||||
|
|
Aside from @ChristopherDavis's answer, you can also do it in a PHP independent way, using .htaccess. Simply add this rule:
Alternative without
The only problem is, two redirects happen here (instead of 1) — (for example) if user visits The advantage is, this never breaks! Plugins may break, but this does not. PS: I use this (short link structure would be
|
||||
|
|