recommended breadcrumb plugins with possibility for hiding “Home” link [closed]

I am using Breadcrumb NavXT plug-in in my pages but now I am facing a problem

I need to hide the “Home” link in some pages. I can do that either by hiding it in CSS or by not creating it at all. in PHP

If I want to use CSS – I dont have any indication for first link and its “>>” separator – there is no id or special class for it

If I go for the PHP solution of not creating it at all in those cases – my problem is I can’t send any parameters to the “bcn_display()” function

Can I do it with my current plug-in or there is a better one?

thanks!

5 Answers
5

Update

Mtekk’s answer does basically what I was suggesting w/o the need to touch the plugin itself, so my answer is of quite theoretical nature. He describes how to do that easily.


I think the easiest thing for doing so as you’re mainly confident with the plugin (saying something minor to change), it would be to hack the plugin and insert a filter hook. Then you can filter based on your needs. If you share the code this might it make even into the original plugin, so you can benefit of updates.

Example:

See file breadcrumb_navxt_class.php. I’ve slightly changed a single function to create a filter:

/**
 * add
 * 
 * Adds a breadcrumb to the breadcrumb trail
 * 
 * @return pointer to the just added Breadcrumb
 * @param bcn_breadcrumb $object Breadcrumb to add to the trail
 */
function &add(bcn_breadcrumb $object)
{
    $doAdd = true;
    $doAdd = do_filter('_bcn_breadcrumb_trail_add_filter', $doAdd, $object);
    if ($doAdd) {
        $this->trail[] = $object;  
        return $this->trail[count($this->trail) - 1];
    } else {
        return $object; // NOTE: violates function return spec but prevents errors later on.
    }
}

The introduced filter is named _bcn_breadcrumb_trail_add_filter. You now can hook to that filter and return FALSE which will prevent adding $object to the breadcrumb trail.

In you filter you can decide based on $object wether or not you want to have it added. That is a bcn_breadcrumb so you can check for it’s title member to look for home or so:

 $object->title

The only thing you need to do is to add some code:

 add_filter('_bcn_breadcrumb_trail_add_filter', function($doAdd, $object) {
     if ($object->title === 'Home'
         && /* this is a page I don't want to have it displayed */) {
         $doAdd = false;
     }
     return $doAdd;
 });

BTW, the author of the plugin is around here from time to time, so probably he has some feedback on this as well.

Leave a Comment