Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i'd like to do this:

www.website.ext/ciccio/pro
www.website.ext/mario/pro
www.website.ext/giuseppe/pro

Why can't i do that? I know.. the slug/child-category "pro" is the same but it is in the different parent categories. So, i don't know what I can do. :/

I tried but it doesn't work because every time wordpress change the category slug to: "child_category-parent_category".

Thanks!

share|improve this question

1 Answer 1

i've found this code, i think it is a good idea:

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;
}

but I have a trouble. It is not working with this structure:

www.domain.com/taco/promotions-taco/2014/title-post/

it become:

www.domain.com/promotions-2014/title-post/ (why???)

But i'd like a structure like this:

www.domain.com/promotions-taco/2014/title-post/

is it possible?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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