Skip to content

Instantly share code, notes, and snippets.

@vietrick
Created September 30, 2022 15:36
Show Gist options
  • Save vietrick/1ceab1b95cffdccaf3cbdbb5a564a21f to your computer and use it in GitHub Desktop.
Save vietrick/1ceab1b95cffdccaf3cbdbb5a564a21f to your computer and use it in GitHub Desktop.
Remove child category in permalinks Wordpress
/*
*
* Remove child categories from permalink in Wordpress
* https://www.vietrick.com/remove-child-category-in-permalink/
*
*/
function remove_child_categories_from_permalinks( $category ) {
while ( $category->parent ) {
$category = get_term( $category->parent, 'category' );
}
return $category;
}
add_filter( 'post_link_category', 'remove_child_categories_from_permalinks', 999 );
// Wordpress Settings > Permalinks > Save Changes to refresh.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment