• Resolved wiwimaster

    (@wiwimaster)


    Hi
    we have defined a decent category tree to structure our posts (recipes). E.g. recipes/pies/apple-pies.
    Now when I make the aforementioned category the primary category, the permalink for a post (“delicious-vegan-apple-pie-recipe”) would look like “/recipes/pies/apple-pies/delicious-vegan-apple-pie-recipe.html”, and the breadcrumb would show recipes > pies > apple pies > recipe name.

    While the breadcrumb works as intended, we’d like to use a shorter permalink, just considering the root category (“recipes”), as otherwise the URL includes a lot of duplicate content (in the example above, 3x pie(s)). At the moment, we make “recipe” the primary category, which probably is not quite the best solution.

    Is there a way how I can bring this to life?

    thanks a lot
    Jan

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    The only way would be to make the slug shorter is by manually changing the page slug delicious-vegan-apple-pie-recipe.html to something short.

    Thread Starter wiwimaster

    (@wiwimaster)

    Not true, there is another way (had to find it myself):

    //Adjust wordpress
    add_filter( ‘post_link_category’, ‘remove_child_categories_from_permalinks’ );
    function remove_child_categories_from_permalinks( $category ) {
    // source: https://wordpress.stackexchange.com/questions/147453/remove-child-category-from-url
    while ( $category->parent ) {
    $category = get_term( $category->parent, ‘category’ );
    }

    return $category;
    }

    //Adjust Yoast SEO:
    add_filter( ‘get_post_metadata’, ‘my_filter_primary_category’, 20, 4 );
    function my_filter_primary_category( $check, $object_id, $meta_key, $single ) {
    // source: https://github.com/Yoast/wordpress-seo/issues/6184
    if ( $meta_key === ‘_yoast_wpseo_primary_category’ ) {
    return $single ? false : array();
    }

    return $check;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show top category in permalink and leaf category in breadcrumb’ is closed to new replies.