WordPress Plugins: sCategory Permalink – select category for permalink generation

Posted by Dmytro Shteflyuk on under WordPress

I’m starting publishing custom WordPress plugins used in this blog, and today it will be “sCategory Permalink”. I like permalink option of WordPress %category% (and using it here), but it has one great limitation – when this option is selected, WordPress uses category with lowest ID for permalink generation! Just imagine following scenario: you have category “Development” (common for all posts related to software building), and several specific categories, for example “PHP”, “AJAX”, “JavaScript”. You have Development category ID greater than any of other categories IDs, therefor specific categories used for URL generation. But one day you decided to start learning Ruby on Rails and post about this in your blog. It’s the problem, because when you will create category “Ruby on Rails”, its ID will be greater then ID of “Development”. Now you have to take decision: to abandon posting in both categories at the same time, or to update “Development” category ID. Lastest can be done in two ways: remove category from WordPress administration area and re-add it (and then you need to go through all of your posts and add needed to this category), or update ID in database (there are several tables related on category ID). But now you can relax! Just download and install plugin!


  1. Download and unpack plugin files to wp-content/plugins/scategory_permalink directory.

  2. Enable “sCategory Permalink” plugin on your Plugins page in Site Admin.

  3. Go to the Options/Permalinks page in Site Admin and use %scategory% option in Custom text field (you can look here for other options). In this blog I’m using /%scategory%/%postname%/.

  4. Now on Write Post page near the categories checkboxes radio button will appear:
    sCategory Permalink
    Select radio button near category which will be used in permalink.

  5. Have fun!


You could always download latest version of the plugin here.

17 Responses to this entry

Subscribe to comments with RSS

said on February 8th, 2007 at 12:26 · Permalink

Amazing plugin. Are you planning a WordPress 2.1 compatible version for the same?

said on February 8th, 2007 at 12:34 · Permalink

Basically the radio buttons show up on the ‘edit post’ page, but not on write new post..

said on February 8th, 2007 at 12:49 · Permalink

Here is the modification needed:-

Inside the function addOptions()


strpos($_SERVER['REQUEST_URI'], 'post.php')


strpos($_SERVER['REQUEST_URI'], 'post.php')||strpos($_SERVER['REQUEST_URI'], 'post-new.php')
said on February 8th, 2007 at 20:36 · Permalink

Огромное спасибо за статью!

said on February 8th, 2007 at 23:00 · Permalink

Только проблемки есть:

1) у меня не появилось переключателей рядом с чек боксом.

2) перестали работать комментарии, точнее ссылки на них… не находит такую страницу и саму страницу, где эта запись.

said on February 8th, 2007 at 23:17 · Permalink

А всё… разобрался… я не обновил .htaccess – сейчас всё ок.

said on February 19th, 2007 at 15:23 · Permalink

Very prolific plugin. Concise and efficient code.
Works without any changes, even sitemaps builded
by another plugin uses new category in permalink.
Definetly a must have.

Now I’m going through all posts, assigning main cat, having fun.

said on February 22nd, 2007 at 01:16 · Permalink

Jayant, thanks for the patch. Will integrate it shortly. Plugin works with WordPress 2.1 without any changes :-)

said on February 23rd, 2007 at 02:46 · Permalink

Great plugin! Works fine with WordPress 2.1 without changes.
Thanks for sharing!

Best wishes,
Caio Proiete

said on March 21st, 2007 at 07:21 · Permalink

Thanks for the plugin! I’m wondering, if, in the case of such master-categories, it wouldn’t be easier to simply define certain categories that are excluded from the permalinks instead of having to define that for all posts?


said on March 21st, 2007 at 08:03 · Permalink

Hi again, I’ve looked at your code and changed it by using this to select the first (in my case usually the only) category assigned to a post apart from the master-categories (here 1/16/32/33). There is a plugin that allows a main category that I am using. Having that and your category checkbox makes the admin panel unintelligible for the authors who aren’t admins. Too much stuff to do before posting a post. So I hope this simplifies it while still benefitting from your great idea and plugin –


I’m sure this could be done far more elegantly by someone who’s more knowledgeable about php and WP, but it does the trick. Maybe someone else will benefit as well.

Thanks again!

said on March 21st, 2007 at 08:04 · Permalink

Hmm, my code is not appearing – any formatting help to post it?

said on March 22nd, 2007 at 08:07 · Permalink

Tobias, sorry for inconvenience, I really forgot about WordPress formatting … features. Currently I’ve adopted my code highlighting plugin to use it in comments. Check formatting tips above the textarea.

To insert code sample please use <code lang="php">$your_code = "here";</code>.


said on March 26th, 2007 at 02:13 · Permalink

Hi Dmytro,

I’m one of the heavy users of your great plugin, and I’ve just found a bug on it, that occurs when someone posts a comment or a trackback on some post.

For some reason, the savePost function gets called on every new comment or trackback, and it ends up updating the post_meta table, and since there is no data to update, it updates to the first category of the post (thus loosing any child category you might have choosen to be the master).

I’ve solved it by just checking if we are on the “post” page, before attemp to save anything.

Here is the solution:

    /** Store category permalink in post meta */
    function savePost($post_ID) {
            Modified by Caio Proiete on 2007-03-25.
            Are we inside post.php or post-new.php?

        if (strpos($_SERVER['REQUEST_URI'], '/post.php') || strpos($_SERVER['REQUEST_URI'], '/post-new.php')) {
                Yes, we are... It's Safe to save/update post_meta table

            $category_permalink = $_POST['category_permalink'];

            $post_category = wp_get_post_cats('', $post_ID);
            if (isset($category_permalink)){
                $found = false;
                foreach ($post_category as $cid)
                    if ($cid == $category_permalink) {
                        $found = true;
                if (!$found)
                    $category_permalink = $post_category[0];
            } else
                    $category_permalink = $post_category[0];

            if (!update_post_meta($post_ID, '_category_permalink', $category_permalink))
                add_post_meta($post_ID, '_category_permalink',  $category_permalink, true);


said on March 30th, 2007 at 11:32 · Permalink

Thank you, guys
I have updated plugin to version 0.2.0, and you could get it
here (yeah, I have changed its location, but old URL would work too). Later I will publish post about other plugins.

said on August 9th, 2007 at 13:52 · Permalink

After using your plugin I’m noticing some bugs. It’s doing the opposite of what the original Word Press was doing. However, it’s actually very manageable this way! Here is how my site is setup and how your plugin is helping it.

My site has 3 main categories, let’s just say “A, B, C” and in them they have sub categories, “cat, dog, mouse”

The main categories have low # category id’s because I created them first. The way the original wordpress would work was that it simply would call on the lowest id #, as you very well know. But now with your plugin, it’s calling on the higher id # which works like this:

If category A’s ID is #10
and category dog’s ID is #22 (and dog is a sub category of A) here is how they show up.

In word press it showed up as http://www.test.com/A/title.html

With your plugin it shows up as http://www.test.com/A/dog/title.html

And that is exactly how I wanted it! This makes the categories very manageable because now I can simply add a new category and it’ll work right away.

With that said, I have not tested if it works without sub categories. I personally have a gaming site, so something like http://www.test.com/news/xbox/ is what I want. Either way, I think this plugin is a life saver

Comments are closed

Comments for this entry are closed for a while. If you have anything to say – use a contact form. Thank you for your patience.