Adds Parent Category back to permalink
-
I have a filter in place to remove the parent category from my permalink structure. When I activate your plugin and give a secondary category, the permalink structure picks up the parent category again, but the permalink only gets the parent category if it is not in same parent. If the secondary cat is in the same parent cat, the permalink does not pull in the parent. Here’s the filter from the functions.php. Can you see something I should be setting differently here?
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 ) { usort( $cats, '_usort_terms_by_ID' ); // order by ID if ( $parent = $cats[0]->parent ) { $parentcats = get_category_parents( $parent, false, '/', true ); $permalink = str_replace( $parentcats, '', $permalink ); } } return $permalink; }
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
The topic ‘Adds Parent Category back to permalink’ is closed to new replies.