Remove the Link in a Breadcrumb

A topic that comes up time to time in support requests is how to unlink a breadcrumb. Typically this is due to having an empty page that exists to facilitate a logical hierarchy. Naturally, linking to this blank page in the breadcrumb trail is not useful. While it is bad form to have a breadcrumb in the breadcrumb trail that is not linked, there is a filter that can facilitate this behavior.

The presented solution is a simplistic example for a single page. However, it can be extended for multiple pages, or taxonomy terms. Finally, rather than being hard-coded, the IDs could come from a post_meta/term_meta field.

The Code

add_filter('bcn_breadcrumb_url', 'my_breadcrumb_url_stripper', 3, 10);
function my_breadcrumb_url_stripper($url, $type, $id)
{
	if(in_array('post-page', $type) && (int) $id === MYPAGEID)
	{
		$url = NULL;
	}
	return $url;
}

After placing this code into your site specific plugin, you will need to update one part of it. Just replace MYPAGEID with the ID of the page you want to remove the link to. That’s it. Simple, right?

-John Havlik

[end of transmission, stay tuned]

8 thoughts on “Remove the Link in a Breadcrumb

    • One way would be to replace $id === MYPAGEID with in_array((int) $id, array(MYPAGEID1, MYPAGEID2, MYPAGEID3)). Where MYPAGEID1, MYPAGEID2, and MYPAGEID3 are your page IDs that you want to remove the link from (note that you can add more IDs by adding a comma after the last ID and adding in the next ID.

      -John Havlik

  1. I did this and it doen’t work. The code ended up looking like:

    if(in_array(‘post-page’, $type) && in_array(array(48, 60), $id))
    {
    $url = NULL;
    }
    return $url;

    Not sure what I am doing wrong.

    • Hi Vince,

      I had a typo in my previous reply, the order of inputs to in_array needs to be swapped. So you should try the following:


      if(in_array(‘post-page’, $type) && in_array((int) $id, array(48, 60)))
      {
      $url = NULL;
      }
      return $url;

      Also note the casting of $id to an integer, that is optional, but will ensure more consistent results (occasionally WordPress returns the ID as a string rather than integer causing strict comparison to fail).

      -John Havlik

  2. Is there another way I can get it to work? Did I put the code in the right spot?

    If you could take a look and let me know I would greatly appreciate it.

  3. Hello John, this code is exactly what I’ve been looking into –but– it also takes out both the linked image used to link to the homepage and the breadcrumb item that I want the link removed from.

    I have two dropdowns on the navbar. Products v and About v (where v is the dropdown indicator.) The About dropdown currently contains two items simplified for sake of discussion: About A and About B.

    // A typical breadcrumb when About v navbar menu is selected…
    [linked image] > About > About B

    The code above works well but as I said it takes out the link on BOTH [linked image] and About when all that is needed is to remove the link for About which again, is linked because it seems neccessary to have a page when creating the menus in WordPress.

    I use settings to remove the links from the last item in each breadcrumb trail so About B in this example will never be linked anyway.

    Comments? Code?

  4. Hi John, How do we go about removing a breadcrumb item based on tax ID? For example I tried using the following:

    function filter_bcn_breadcrumb_types( $this_type, $this_id ) { 
        if($this_id == 2508) {
            return null;
        } else {
          return $this_type; 
        }  
    }; 

    ..but it has no effect. Is this the wrong filter to use for this? Many thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *