• Resolved ryanck

    (@ryanck)


    Hi there,

    I was wondering if anyone could help with the code or configuration that removes the “category/“ from the breadcrumb links.

    Note that I just need for the breadcrumb links not for the full WordPress.

    Thanks I’m advance for your help.

    Have a good day.

Viewing 6 replies - 1 through 6 (of 6 total)
  • At least you can do that with CSS:

    Body has classes relating with categories:

    body.category .container-of-the-breadcrumbs {display:none} /*or visibility:hidden if it works better with your layout*/

    Each category has class like category-mycategory so you should add more rules.

    Archive page, where all are listed in one page, needs also corresponding rules

    The container is not the same as mine, so I can’t say how exactly you should define the CSS. Categories are different. So I can’t help more.

    Plugin Author John Havlik

    (@mtekk)

    @ryanck: I take it as you are using a page rather than the category archives WordPress normally generates. If you are doing that, you probably want to make all of the links WordPress generates for category archives. But, if you insist and want to only affect the breadcrumb links, you can use the bcn_breadcrumb_url filter. See https://mtekk.us/archives/guides/link-to-a-page-rather-than-the-category-archive-in-a-breadcrumb/ for an example on how to use this filter.

    @tapiohuuhaa: I don’t think @ryanck was talking about hiding the category breadcrumbs for a post. That can be achieved by making sure the “Hierarchy Display” option for the post type in question is unchecked.

    Thread Starter ryanck

    (@ryanck)

    Hello,

    Thanks a lot for your help and John, what an awesome plugin you´ve built man! Thank you for this!

    @mtekk is right. What I want is to get the link URL without the “category/”.

    I´ve been trying few things in the weekend and I found out a solution in this site: https://lyle.troxell.com/pen/articles/2011/07/28/breadcrumb_navxt_categories/

    So I ended up with this code in class.bcn_breadcrumb_trail.php:
    Line 427, 452 and 569:

    $this->maybe_add_post_type_arg(str_replace("category/", "", get_term_link($term, $taxonomy))))
    $this->maybe_add_post_type_arg(str_replace("category/", "", get_term_link($term, $taxonomy))), $id));
    $this->maybe_add_post_type_arg(str_replace("category/", "", get_term_link($term, $taxonomy))));

    Hope it makes sense.

    Have a nice day.

    • This reply was modified 7 years, 1 month ago by ryanck.
    • This reply was modified 7 years, 1 month ago by ryanck.
    • This reply was modified 7 years, 1 month ago by ryanck.
    Plugin Author John Havlik

    (@mtekk)

    @ryanck: I strongly recommend against modifying any of the files distributed by Breadcrumb NavXT. Your changes will be overwritten when you update Breadcrumb NavXT. Instead, you should use the bcn_breadcrumb_url filter to remove the category link. For example, the following placed in a site specific plugin should achieve the same result without modifying the plugin:

    add_filter('bcn_breadcrumb_url', 'my_breadcrumb_url_changer', 3, 10);
    function my_breadcrumb_url_changer($url, $type, $id)
    {
        if(in_array('category', $type))
        {
            $url = str_replace("category/", "", $url);
        }
        return $url;
    }
    Thread Starter ryanck

    (@ryanck)

    Wow @mtekk thank you so much. It worked perfectly man.

    Awesome plugin and awesome support.

    Thanks!

    Have a nice day.

    I took out of usage hierarchy. But the problem was that information about parent page was missing.

    A small trick with CSS helped:

    I have just one category and I put with CSS the name of the category before the current page item

    body.single-post .current-item::before {content:’Ristikkoartikkelit > ‘;}
    https://www.sanaristikkofoorumi.net/wordpress/suoraan-netissa-ratkottavat-ristikot-ja-niiden-toimivuus/

    Now the breadcrums tells that the current page is logical parent of the page Ristikkoartikkelit. Not exactly the same style and Ristikkoartikkelit is not linked but the information is ok.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Remove /category from breadcrumbs links’ is closed to new replies.