For each post, author can choose which category is used in permalink.
WordPress 3.0 comes with a new filter that lets us customize what is used for each permalink structure tag, other than WordPress default.
One of these permalink structure tags is %category%
. By default, WordPress always use the category with lowest ID, making %category%
impractical for SEO optimization.
Hikari Category Permalink allows post authors to choose among each post’s categories, which of them is used in that post permalink, giving much more flexibility and power to permalinks.
This plugin is a fork of Dmytro’s sCategory Permalink. It has all original features and is compatible with original options, while being more stable and simple, and also fixes 2 recurring bugs.
%category%
permalink.Hikari Category Permalink requires at least WordPress 3.0 and PHP5 to work. It has backward compatibily for WordPress 2.8 and 2.9, but they are deprecated and I don’t support them officially. Setting category permalink also requires JavaScript enabled.
If you have Dmytro’s sCategory Permalink plugin installed, first deactivate it. Hikari Category Permalink doesn’t conflict with the legacy plugin, but I don’t recommend keeping both activated.
Once you are ready to install, you can use the built in installer and upgrader, or you can install the plugin manually.
/wp-content/plugins
folder. Make sure the plugin has its own folder (for exemple /wp-content/plugins/hikari-category-permalink/
).%category%
tag. For an exemple, you can use /%category%/%post_id%/%postname%/
.If you have to upgrade manually, simply delete hikari-category-permalink
folder and follow installation steps again.
If you are using Dmytro’s sCategory Permalink plugin, just deactivate it and activate Hikari Category Permalink.
And once the upgrade is done, if you are using WordPress 3.0 or above, go to Settings > Permalink and replace legacy %scategory%
tag to stantard %category%
!
To uninstall just deactivate the plugin, or delete its folder.
There’s no wp_options option stored, posts category permalinks are stored as postmeta. Currently there’s no automatic way to delete these postmeta if you don’t need them anymore, this feature will be added in a future release.
%category%
tag in my permalink structure?You still can set category permalinks when creating and editing posts, but their permalinks won’t have any category on them. When you decide to use %category%
in your permalinks, saved categories will start being used.
Your posts URLs will of course change, and not have category on them anymore. But postmeta will remain saved and you’ll still be able to set them, and when you decide to use the %category%
tag again they’ll be used.
Hikari Category Permalink just does nothing and send the permastruct back to WordPress to deal with it in its default. WordPress default is use the category with lowest ID.
It’s inefficient because WordPress generates and parses permalinks dynamically, they aren’t stored, and to parse it uses general expressions and database queries. If you only have string tags in posts permalinks, there’s no way for WordPress to distinguish posts from pages, and then it must use slower methods to identify a post.
Hikari Category Permalink uses the standard %category%
tag and doesn’t require any rewrite rules tweaking, all its tweaks are in permalink creation (get_permalink()
function) and not in parsing, so your permalink structure has the same weakness it would have if the plugin wasn’t being used. I suggest adding an integer tag somewhere in the structure (begining, middle or end, if you use more than 1 string tag I suggest adding an int tag between them). My prefered one is %post_id%
, because its meaning is directly related to the post, and you have quick view to a post ID when you can see its permalink.
sCategory Permalink is a great plugin, it was original, unique, and pionner. For long we were in need of a category-in-permalink solution than the simple the-one-with-lowest-ID WordPress offers. Dmytro was able to imagine a much better solution and implement it.
But the plugin was bugged, it’s in v0.6.2 for a long time, and I was still using v0.3.0, because any version above it was generating 404 for me in any post, while v0.3.0 generates 404 when I use multipaged comments. Dmytro offered the plugin for free and made it almost perfect, but it wasn’t being supported anymore and he didn’t answer my contact attempts, so I decided to fix it.
I wasn’t able to fix the original bugs, but discovered that with a new filter inside get_permalink()
, the code with original bugs wouldn’t be needed anymore, the plugin would be much simpler to tweak WordPress and permalink generation would be much more flexible. I opened a ticket in WordPress trac requesting the new filter, and it was added to 3.0! 😀
Since I can’t contact Dmytro, I just forked the plugin and enhanced it.
Yes, I did that 😛
It uses the same postmeta, so all your existing category permalinks will be used, and new ones will use the same name, all simple. And with the advantage of 404 errors being totally gone, since Hikari Category Permalink doesn’t touch rewrite rules! 😀
And one more thing, once the upgrade is done, if you are using WordPress 3.0 or above, go to Settings > Permalink and replace legacy %scategory%
tag to stantard %category%
!
It indeed supports and I’ve been using in it, even 2.8 may work. But when used in WordPress below 3.0, the legacy %scategory%
tag must be used, standard %category%
doesn’t work, and therefore 404 error when multipages comments are used may occur. I just hacked my WordPress core and added the filter that only 3.0 has natively, but I won’t explain other people how to do it in 2.9 and won’t support any bug on it, I only support Hikari Category Permalink in WordPress 3.0 and above 🙂