Hopefully another simple one, I have some nested categories, like this:

- category-a
    - category-b

The permalink for category-c is as follows:


What I'd really like is for the permalink to not include any parent categories, instead it would become this:


Is there a way this can be achieved? I have some categories that do nothing but group sub-categories together, thus I don't really want them displaying to my users.

Many thanks!


1 Answer 1


The following code changes all links to category archives so they don't include the parent category:

add_filter( 'category_link', 'wpse7807_category_link', 10, 2 );
function wpse7807_category_link( $catlink, $category_id )
    global $wp_rewrite;
    $catlink = $wp_rewrite->get_category_permastruct();

    if ( empty( $catlink ) ) {
        $catlink = home_url('?cat=' . $category_id);
    } else {
        $category = &get_category( $category_id );
        $category_nicename = $category->slug;

        $catlink = str_replace( '%category%', $category_nicename, $catlink );
        $catlink = home_url( user_trailingslashit( $catlink, 'category' ) );
    return $catlink;

Add the code to the functions.php of your theme.

  • That's exactly what I was after, does exactly what I need without editing any core files and without using a plugin (which is preferable for me). Many thanks @Jan Fabry Commented Jan 26, 2011 at 13:00
  • Will your code work for removing parent category page permalink as well?
    – Mars
    Commented Mar 22, 2011 at 16:48
  • @Mars: I'm sorry, I don't understand what you want to ask. If you have a subcategory at /category/fruit/banana/ the links will be changed to /category/banana/. The /category/fruit/ archive will stay at that location.
    – Jan Fabry
    Commented Mar 22, 2011 at 17:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.