How to Remove post_type From Breadcrumb NavXT URLs

Beginning with Breadcrumb NavXT 5.3.0, post type archive support was enhanced with the addition of the post_type query argument under various circumstances. Usually, this occurs when the post type is not the primary post type for the taxonomy (e.g. it is not the first post type in the object_type array for the taxonomy), or for date archives. While this is arguably the correct behavior, it is not right for every circumstance.

Breadcrumb NavXT 5.4.0 introduces a new filter, bcn_add_post_type_arg, which furnishes the ability to override the decision on when to include the post_type query argument. This article covers the basic usage of this filter, along with some hints for more advanced uses.

Basic Code

The most basic code, listed below, disables adding the post_type query argument for all resources.

add_filter('bcn_add_post_type_arg', 'my_add_post_type_arg_filt', 10, 3);
function my_add_post_type_arg_filt($add_query_arg, $type, $taxonomy)
{
return false;
}

To get started quickly, just copy and paste the above code into a site specific plugin and start playing.

Hints for (More) Advanced Uses

From the basic code above, notice that there are three parameters passed into the filter. The first is the decision Breadcrumb NavXT was going to make in regards to adding the post_type query argument. The second is the name of the post type that is under consideration for addition to the URL. Lastly, the third parameter is the name of the taxonomy, if applicable, for the archive the URL points to. With this information, more complex filtering/decision making can be achieved.

For example, it is possible to enable the post_type query argument for only specific post types, or for specific taxonomy archives. Or, the post_type query argument can be enabled for all but a specific post type or taxonomy. All it takes is a little conditional logic that looks at the second and third parameters of the filter function.

-John Havlik

[end of transmission, stay tuned]

3 thoughts on “How to Remove post_type From Breadcrumb NavXT URLs

    • For Breadcrumb NavXT 5.3.0 and 5.3.1, you could use the bcn_breadcrumb_url filter and call remove_query_arg('post_type', $url); within it to remove the query argument. This will be equivalent to basic code presented above.

      -John Havlik

  1. I create post type called “Video” beside post. Both post type “Video” and standard “Posts” have supports custom taxonomy “Director”.

    Then I add a new post in standard “Posts”, e.g. “How to be…” that added with a name [John] for “Director”.

    Then, I also add a new post in post type “Video”, e.g. “The making video” and add just same name as director above.

    When I click the archive of director name, the breadcrumbs shows :
    Home > Video > John

    If I add a new post again in standard “Posts” not “Video”, the breadcrumbs for that director name will shows:
    Home > John

    My question: Can I do something in order to remove “Video” from breadcrumbs?

    For single post both in “Video” or “Posts”, I see achieved condition like:
    Home > Video > <em>The making video</em>
    or
    Home > Tutorial > <em>How to be...</em>

    As I explain above my trouble is the breadcrumbs archive for taxonomy “Director” that have changed every I add a new post either in post type “Video” or standard “Posts”.

    Sorry about my english.

Comments are closed.