How to remove "blogs » user's blog" from breadcrumbs

Note: the better way to avoid this problem is to not use the blog module. Blog module is intended for a site with multiple blogs. For single-user blogs, using story or a custom content type is sufficient.

I'm the only one blogging at my website, so at my site the "blogs » user's blog" part of the breadcrumb is redundant (and a bit confusing).

To remove it, I've added this to template.php:

<?php
/**
* Remove links to individual blog from breadcrumbs.
*
* (This is an uggly solution, prone to break since it identifies blog nodes by matching a string in
* the breadcrumb. Better would be to check if node type is 'blog' But I don't know how to get that info here.
*
* Also note that it does not change the menu, so "my blog" is still present there. (I suspect that 'menu_set_location'
* (as used in blog.module blog_view) may be the function to use to change this.))
*/
function phptemplate_breadcrumb() {
   
$breadcrumb = drupal_get_breadcrumb();
    if (
$breadcrumb[1] == l('blogs',t('blog'))){         // For blog nodes...
       
unset($breadcrumb[2]);                     // ...remove "user's blog"...                            
       
unset($breadcrumb[1]);                  // ...and "blogs".
   
}
   
// Now call the original theme with this modified breadcrumb array, to get formatting.
  
return (theme_breadcrumb($breadcrumb));
}
?>

For Drupal 6 the function

aarakast - May 25, 2008 - 19:58

For Drupal 6 the function could look like this:

<?php
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
*   An array containing the breadcrumb links.
* @return a string containing the breadcrumb output.
*/
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty(
$breadcrumb)) {
    if (
$breadcrumb[1] == l('Blogs',t('blog'))){  // For blog nodes...
     
unset($breadcrumb[2]);                      // ...remove "user's blog"...                            
     
unset($breadcrumb[1]);                      // ...and "blogs".
   
}
   
// Now call the original theme with this modified breadcrumb array, to get formatting.
   
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}
?>

--
aarakast.de

Changed one line...

Mobile Michael - July 24, 2008 - 12:31

aarakast, thanks a lot. You saved my day.

I ran into the same issue with the trilingual website www.ArtAndAid.org. The above solution worked fine for English, but not for German. After I changed the 2nd if-statement to

if ($breadcrumb[1] == l(t('Blogs'), 'blog')){

it now seems to work fine for all languages. So the complete function in template.php now looks like this:

function phptemplate_breadcrumb($breadcrumb) {

  if (!empty($breadcrumb)) {
    if ($breadcrumb[1] == l(t('Blogs'), 'blog')){    // For blog nodes...
      unset($breadcrumb[2]);                      // ...remove "user's blog"...                            
      unset($breadcrumb[1]);                      // ...and "blogs".
     
    }
    // Now call the original theme with this modified breadcrumb array, to get formatting.
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

Just use the Custom Breadcrumbs module!

spiffyd - August 20, 2008 - 07:18

Just use the Custom Breadcrumbs module!

http://drupal.org/project/custom_breadcrumbs

 
 

Drupal is a registered trademark of Dries Buytaert.