I am working to redesign a site and would like to rework the permalink structure for the category pages only. Right now they are using:


I would like to switch this to:


When doing this though, I don't want to change any of the post URLs that are currently /year/month/post-name. Is there a way to change the category permalinks, but not the post links?

A few comments too:

  • I know I will likely have the restructure the categories to be in parent/child form, since they currently are not.

  • I thought about using custom post types, but I would rather not do that since it doesn't seem like the best use here.

  • Did you play with the optional settings yet if not try that. Location: Settings > Permalink – user47236 Feb 6 '14 at 17:14

is rare, but it would have to default as you run you want. This forces the operation that you need

function my_category_link( $termlink, $term_id ) {
  $term = get_term( $term_id, 'category' );
  $ancestors = get_ancestors($term_id, 'category');
  if( !count($ancestors) ) return $termlink;

  $hierarchical_slugs = array();
  foreach ( (array)$ancestors as $ancestor ) {
    $ancestor_term = get_term($ancestor, 'category');
    $hierarchical_slugs[] = $ancestor_term->slug;
  $hierarchical_slugs[] = $term->slug;
  return home_url( user_trailingslashit(implode('/', $hierarchical_slugs), 'category') )."\n";

add_filter( 'category_link', 'my_category_link', 9, 2 );

to restructure the categories:

Assign parent category to all posts that are already assigned to child category

| improve this answer | |
  • thanks. I assume I just paste that into my theme's function.php file? When I do that it seems to restructure the permalinks for just the categories, which is perfect. They all lead to a page that outputs a 'Post not found' error even though I know there are posts that have those categories. Anything I am missing? – Andrew Feb 6 '14 at 17:47
  • hey @ Andrew, Test / wp-admin/options-permalink.php in the "Base Category" put "." unquoted – Salem Terrano Feb 6 '14 at 18:33
  • @ Salem, I am not sure I understand. Are you wanting me to edit the options-permalink.php file? I thought you never really wanted to change core wp-admin files. Maybe I am misunderstanding though. Thanks! – Andrew Feb 6 '14 at 18:57
  • no, from the manager. from url example.com/wp-admin/options-permalink.php – Salem Terrano Feb 6 '14 at 20:14
  • wordpress.org/ideas/topic/remove-category-base-from-permalinks ... sorry, my English is very bad because translate.google use – Salem Terrano Feb 6 '14 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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