Created
September 30, 2022 15:36
-
-
Save vietrick/1ceab1b95cffdccaf3cbdbb5a564a21f to your computer and use it in GitHub Desktop.
Remove child category in permalinks Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* 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