• Resolved dsonesuk

    (@dsonesuk)


    I have seen several topics mentioning the old method with examples provided, but i require new example using bcn_after_fill, I got as far as accessing fields object array, but searching identifying specific array elemrnt is beyond me, as they are protected. I can remove no problem, but the middle part i have found no example to do this.
    Note: breaking hierarchy of breadcrumbs by removing Uncategorized category will not be issue, as by using custom permlinks, having Uncategorized show, breaks the hierarchy anyway, because custom url will place it from domain root.

    This should be placed as sticky topic at top, as many seem to ask the same question on how to do this or similar.

    https://www.ads-software.com/plugins/breadcrumb-navxt/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author John Havlik

    (@mtekk)

    The type member array of each bcn_breadcrumb object in the bcn_breadcrumb_trail::breadcrumbs array should be publicly accessible. Additionally, you can use the bcn_breadcrumb::get_title() and bcn_breadcrumb::get_id() public functions to help you determine if the breadcrumb is the one you want to remove.

    Thread Starter dsonesuk

    (@dsonesuk)

    $trail
    add_action(‘bcn_after_fill’, ‘foo_pop’);

    function foo_pop($trail) {

    }

    which gives bcn_breadcrumb_trail, works! with var_dump() it shows me all the the info i wish to access, it shows all titles, id as protected or private, I can’t loop through to compare values i wish to use to identify the breadcrumb i wish to remove, WHY? because they are protected or private.

    bcn_breadcrumb::get_title()
    bcn_breadcrumb::get_id()

    Do nothing but throw up error, if you had bothered to supply example in what context these are supposed to be used, this would not have happened, so I guessed, most likely wrongly, and here we are again.

    Thank again for any useful help

    Plugin Author John Havlik

    (@mtekk)

    Since various filters are run on the ID and title, they are only accessible via get_ and set_ functions. This is a very common OOP practice.

    You can’t directly call bcn_breadcrumb::get_title(), since it is not a static function. That notation was just to let you know that it is a member function within bcn_breadcrumb. For your foo_pop function you need to do something like the following:

    function foo_pop($trail)
    {
    	foreach($trail->breadcrumbs as $breadcrumb)
    	{
    		if($breadcrumb->get_title() === 'blah')
    		{
    			//do something
    		}
    	}
    }

    Thread Starter dsonesuk

    (@dsonesuk)

    Now that more like It! Thanks, I knew previous coding was class access, the coding example, I’m sure I tried that? but never mind, it works now, excellent.

    add_action('bcn_after_fill', 'exclude_these_crumbs');
    
    $exclude_ids = [1,126];
    
    function exclude_these_crumbs($trail) {
        global $exclude_ids;
    
        foreach ($trail->breadcrumbs as $key => $breadcrumb) {
            if (in_array($breadcrumb->get_id(), $exclude_ids)) {
                array_splice($trail->breadcrumbs, $key, 1);
            }
        }
    }

    @dsonesuk
    can you clarify that code by any chance? It gives me syntax error in my functions.php …

    I am in similar boat, where I need to hide “U.S.” in my crumbs for news in

    Site > U.S. > California > Los Angeles

    Need those in the U.S. category vs World category, but redundant for the breadcrumbs as 95% of the U.S. index matches the main one. In my case I want to hide category 19 … but this gives me syntax error. I know I’m missing the duh thing here …. any suggestion?

    add_action('bcn_after_fill', 'exclude_these_crumbs');
    
    $exclude_ids = [19];
    
    function exclude_these_crumbs($trail) {
        global $exclude_ids;
    
        foreach ($trail->breadcrumbs as $key => $breadcrumb) {
            if (in_array($breadcrumb->get_id(), $exclude_ids)) {
                array_splice($trail->breadcrumbs, $key, 1);
            }
        }
    }

    Issue seems to be this item floating in the middle
    $exclude_ids = [19];

    thanks for any feedback, if you have the time. If not, totally understand!

    Oh…. actually – just discovered the ‘bender’ add-on … that totally works for what I need – and awesome!!!

    Thread Starter dsonesuk

    (@dsonesuk)

    “Issue seems to be this item floating in the middle
    $exclude_ids = [19];”

    No syntax error shows from current example used? from editor used or from php display errors settings, so I don’t currently see why you have syntax error showing?

    Anonymous User 7501994

    (@anonymized-7501994)

    @neotrope can you share the link for this “bender” please, I can’t find it…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Remove specific category (uncategorized) or page from breadcrumbs’ is closed to new replies.