Reorder WordPress Link Categories

Update 1/14/2011: According to Dustin Gurley, this still works in WP3 w/ minor modification. Thanks, Dustin.

Update 1/30/06: a plug-in now exists to handle this.

WordPress lacks the ability to specify the exact order that link categories appear in the sidebar. The get_links_list() function can only order categories by name or id, and this limitation becomes annoying when you create your categories out of order (you can no longer order by id) or want to rename your categories (“Junk” has to appear before “My Favorite Links”).

Here’s how to completely customize the order of your link categories:

  1. Open up your WP database with a database admin tool (eg. MySQL Query Browser or phpMyAdmin).
  2. Find the wp_linkcategories table and the row of the category you’d like to appear first.
  3. Update the cat_name field of that row, prefixing the existing name with the HTML comment: <!--01--> (eg. My Stuff becomes: <!--01-->My Stuff)
  4. Update the rest of the rows in the order you want those categories to appear, prefixing each name with <!--02-->, <!--03-->,

Now when get_links_list() orders categories by name, they’ll be in order by the numbers in the comments, which will be hidden by the browser.

Note that you can’t simply enter the comment within WP because it will escape the greater/less than characters, breaking the format of the comment. For the same reason you won’t be able to change the edited category names within WP without breaking the comments, though you can remove the comments and go back to ordering by name or id.

Maybe someone will make a plug-in to do this from within the WP interface.

18 thoughts on “Reorder WordPress Link Categories

  1. says:

    What if you want do alphabetize everything, but you want to put one link at the bottom? (your Junk link)? Simply put everything else to <!--00--> and set the bottom one to <!--01-->.

    But Hawke…I already have 10 categories. I don’t want to edit them all manually! Whatever can I do!

    The following SQL statement will add <!--00--> in front of all your current category names:

    UPDATE `wp_linkcategories` SET cat_name = CONCAT('<!--01-->', cat_name);

    Be careful with this statement… might want to back up the table or be ready to hand edit if you mess it up. Worked fine for me, but *do at your own risk*! Don’t come bothering me or Steve if you blow it.

    Thanks for the tip, Steve.

  2. Indeed. Thanks for the hack! I’ve been wondering how to change the order of my categories without renaming them to something funky for a while now.

  3. Schwarzemann says:

    Much like everyone else I thank you. Just one more measure of control I get to have over my blogging experience…

  4. rob says:

    this is a necessity of many programmer;
    why yet isn’t a default feature?
    how for pages.

  5. says:

    This is great. Thanks. Of course, after using this hack, it’s necessary to make all changes in mysql rather than through the WP interface. Or, at the very least, you now have to revisit the database to rename the category all over again. A small price to pay for the flexibility.

  6. Antz says:

    Thanks, really appreciate it!

    About what Hawke said, instead of adding all the to the categorys, you could make the category you want to display last have a comment like <!--z-->, that would surely work.

    Thanks again!

  7. says:

    No need to actually go into the db manager– you can rename the categories within wordpress manager with this tag.

  8. says:

    sorry, danee — but editing within wp-admin (at least in version 2.0, ahem — somebody hasn’t upgraded lately), you’ll end up with


    wp “conveniently” escapes the characters, as mentioned above.

  9. says:

    Thanks, I can’t believe there isn’t a plugin for this yet. There still isn’t a way to export a blogroll either. Great Hack! Saves the trouble of going into the sidebar and placing get_links_list() everywhere!

    What happens if some categories are edited with the comment and some aren’t? Like if I add a new category from the admin panel.

    Thanks again!

  10. Ryan says:

    This no longer works. Even updating it within the database in something like phpAdmin, the link name gets printed out and the extra dash of the HTML comment removed, so that it shows in the sidebar.

  11. says:

    @Ryan: Which version of WP are you running? Have you tried with a non-web-based tool like MySQL Query Browser? It wouldn’t shock me if they did start escaping on output rather than input, which they do now.

  12. says:

    I’m a complete and utter hack when it comes to this kind of stuff so I honestly have NO CLUE what I’m doing. That’s why I thank my lucky stars every day for support forums and sites like this.

    Anyway, I tried the initial suggestion, but as Ryan pointed out, it no longer works. The ‘‘ was showing up along side the link name.

    So I figured I’d try putting in a space in front of the name and it worked! I had about 20 links total within 3 different categories and I wanted to rearrange just a handful of them.

    For the one I wanted to appear at the top of the category, I put the most number of spaces, and then decreased the spaces as the listing went down.

    And sure enough, when I checked my site, the links appeared in the desired order and the name was aligned left, along with all the other links.

    Anyway, I hope this helps others that are searching for a way to rearrange the links in the Blogrolls!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.