3

I'm altering breadcrumbs using the theme_menu_breadcrumb_alter function and was wondering what can I do to make the last breadcrumb non-clickable (i.e. it should be just text, not a link).

I tried making the href value to an empty string but that just returns a link to the base URL.

How can I do this?

4
  • Could you explain why would you want that? And have you considered altering (or at least inspecting) it's tpl file?
    – Mołot
    Commented Aug 6, 2015 at 14:51
  • sure, since i'm on that page I don't need to make that last breadcrumb clickable
    – pzirkind
    Commented Aug 6, 2015 at 14:52
  • 1
    That's not always true. For example if there are filters on page, or content that changes in response to user's actions, clicking last breadcrumb element is a way to start clean. Also, it's convenient point to copy link location from, if access to address bar is somehow problematic (some mobile browsers for example). So it has some uses. And even if unneeded - does it really bother you?
    – Mołot
    Commented Aug 6, 2015 at 14:54
  • very true, the question is what if my client wants me to ;)
    – pzirkind
    Commented Aug 6, 2015 at 16:55

1 Answer 1

4

If anyone else is looking for this, here is one way to solve it:

In template.php add the following function

function theme_breadcrumb($variables){
    // get an array with all the breadcrumbs (and their html)
    $breadcrumb = $variables['breadcrumb'];

    // remove the html from the last one and put it into new variable
    $cur_page_brdcrmb = strip_tags(end($breadcrumb));

    //remove the last element from the original breadcrumb array
    array_pop($breadcrumb);

    // add our html free breadcrumb to the array
    $breadcrumb[] = $cur_page_brdcrmb;

    // build the output and return it
    $output = '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
    return $output;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.