We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20557
    • 43 Posts
    I originall posted this in the Navigation & Tagging/Taxonomy forum, but I got no response. I got around this for now by specifying overflow:hidden; in the CSS for the DIV containing the breadcrumbs, but this is less than ideal...

    Does anyone know how I can modify the Breadcrumbs snippit to truncate long breadcrumbs?

    Hi,

    When using the breadcrumbs snippit, is there any way to specify a maximum length for breadcrumbs and have the link ’truncate’ after the length is reached.

    For example:

    Home > News > This is a very very long breadcrumb link

    would become

    Home > News > This is a very very...

    Thanks,
    Matt
      • 18374
      • 69 Posts
      I took a look at the Breadcrumbs snippet and found this on line 414:

      $pretemplateCrumb .= '<a class="'.$crumbClass.'" href="'.$modx->makeUrl($c['id']).'" title="'.$title.'">'.$text.'</a>';


      So, it looks like the $text variable contains the data you want to truncate. You could add the following right before line 414 to truncate it. I haven’t tested this but should get you pretty much there:

      if (strlen($text) > x) {
          $text = substr($text, 0, x);
          $text .= "…";
      }
      


      Just replace x with the number of characters you want to display in the link.

      EDIT: On a closer look you might want to add the code before line 390 - that way $text will be updated if you’re using a link or a span.
        • 20557
        • 43 Posts
        Excellent!  Thanks Mark, it works perfectly as it is.  As you suggested, I inserted the code on line 390 before the "// Make link" comment.

        I really should learn some php...  smiley

        Thanks again for your help.
        Matt