I'm looking for a way to determine where the users are coming from to build the breadcrumb for a page.

Is there something I can do with hook_breadcrumb_alter(&$active_trail, $item), or should I use the Flag module or any activity tracker module?

  • you can use php for that : if(isset($_SERVER['HTTP_REFERER'])) { $previous = $_SERVER['HTTP_REFERER']; } that might not work on HTTPS Commented Feb 13, 2018 at 9:13

1 Answer 1


If you have control over the Urls linking to your target page, append a page-specific parameter. Suppose the page you are linking to is http://www.example.com/target-page:

  • On the first referring page, make this Url: http://www.example.com/target-page?referer=page-1
  • On the second referring page, make this Url: http://www.example.com/target-page?referer=page-2

Then in your hook_menu_breadcrumb_alter function, the referer will be available in the $_GET variable, and you will be able to do something like this in the template.php file for your theme:

function mytheme_breadcrumb(&$variables) {

  if (request_uri() == '/target-page') {
    switch($_GET['referer']) {
      case 'page-1':
        $variables['breadcrumb'][] = l('First referring page', '/page-1');
      case 'page-2':
        $variables['breadcrumb'][] = l('Second referring page', '/page-2');

If you don't want to add parameters to the Url, and are not using HTTPS, you could use the approach above except with $_SERVER['HTTP_REFERER'] in the switch statement. Or alternatively, you could set a cookie on the referring pages and read it on the target page.

The example above is probably the easiest way to manipulate breadcrumbs but strictly speaking, there should not be business logic in a theme function. See these questions for more detailed info on how to manipulate breadcrumbs:


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.