Title: Remove Parent Categories
Last modified: August 31, 2016

---

# Remove Parent Categories

 *  [nickfoti](https://wordpress.org/support/users/nickfoti/)
 * (@nickfoti)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/remove-parent-categories/)
 * I’m using a popular function to remove the parent category from the permalink:
 *     ```
       add_filter( 'post_link', 'remove_parent_cats_from_link', 10, 3 );
       function remove_parent_cats_from_link( $permalink, $post, $leavename )
       {
           $cats = get_the_category( $post->ID );
           if ( $cats ) {
               // Make sure we use the same start cat as the permalink generator
               usort( $cats, '_usort_terms_by_ID' ); // order by ID
               $category = $cats[0]->slug;
               if ( $parent = $cats[0]->parent ) {
                   // If there are parent categories, collect them and replace them in the link
                   $parentcats = get_category_parents( $parent, false, '/', true );
                   // str_replace() is not the best solution if you can have duplicates:
                   // myexamplesite.com/luxemburg/luxemburg/ will be stripped down to myexamplesite.com/
                   // But if you don't expect that, it should work
                   $permalink = str_replace( $parentcats, '', $permalink );
               }
           }
           return $permalink;
       }
       ```
   
 * Amp pages work fine for posts that do not have a parent category, however those
   that are tagged with a category that has a parent redirect to the original page
   url sans /amp/.
 * Any ideas on how I can fix this?
 * [https://wordpress.org/plugins/amp/](https://wordpress.org/plugins/amp/)

The topic ‘Remove Parent Categories’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [parent](https://wordpress.org/support/topic-tag/parent/)
 * [parent category](https://wordpress.org/support/topic-tag/parent-category/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [remove](https://wordpress.org/support/topic-tag/remove/)

 * 0 replies
 * 1 participant
 * Last reply from: [nickfoti](https://wordpress.org/support/users/nickfoti/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/remove-parent-categories/)
 * Status: not resolved