I am using Drupal 6.17 and want to get rid of "HOME" in the breadcrumb output...
eg:
$breadcrumb= PRODUCTS // SOFTWARE // FEATURES
instead of
HOME // PRODUCTS // SOFTWARE // FEATURES
I am using Drupal 6.17 and want to get rid of "HOME" in the breadcrumb output...
eg:
$breadcrumb= PRODUCTS // SOFTWARE // FEATURES
instead of
HOME // PRODUCTS // SOFTWARE // FEATURES
Here's a Drupal 7 version:
/**
* Get rid of Home in breadcrumb trail.
*/
function <themename>_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
array_shift($breadcrumb); // Removes the Home item
$output .= '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
return $output;
}
}
Override the breadcrumb in your theme's template.php file:
/**
* 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)) {
array_shift($breadcrumb); // Removes the Home item
return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
}
}
(Replace yourtheme
with your theme's actual machine name...)
Add the following to your theme's yourtheme.theme
file:
/**
* Prepares variables for `breadcrumb.html.twig`.
*/
function yourtheme_preprocess_breadcrumb(&$variables){
// Remove 'Home' from breadcrumb trail.
if (count($variables['breadcrumb'])) {
array_shift($variables['breadcrumb']);
}
}
Add the following to your theme's theme-settings.php
:
<?php
/**
* Implements hook_form_system_theme_settings_alter().
*/
function yourtheme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {
$form['theme_settings']['hide_home_breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Hide <em>Home</em> in breadcrumb trail'),
'#default_value' => theme_get_setting('hide_home_breadcrumb', 'yourtheme'),
);
}
Add the following to your theme's yourtheme.theme
file:
/**
* Prepares variables for `breadcrumb.html.twig`.
*/
function yourtheme_preprocess_breadcrumb(&$variables){
// Remove 'Home' from breadcrumb trail.
if (!empty(theme_get_setting('hide_home_breadcrumb', 'yourtheme')) && count($variables['breadcrumb'])) {
array_shift($variables['breadcrumb']);
}
}
If you want the Home button to be disabled by default when the theme is installed, add the following to your theme's yourtheme.settings.yml
:
# Hide 'Home' in breadcrumb trail by default.
hide_home_breadcrumb: 1
If you're working with an existing site, and are using Drupal Configuration Syncing with Drupal 8, you should also add/modify the yourtheme.settings.yml
file in the sync directory, and run drush cim sync
.
In some cases, a site design might call for hiding the Home link if it is the only item in the breadcrumb trail, and when there are other items in the breadcrumb trail to leave Home in the breadcrumb trail.
Here's how to implement the radio buttons depicted above:
Add the following to your theme's theme-settings.php
:
<?php
/**
* Implements hook_form_system_theme_settings_alter().
*/
function yourtheme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {
$form['breadcrumbs'] = [
'#type' => 'details',
'#title' => t('Breadcrumb'),
'#open' => TRUE,
];
$form['breadcrumbs']['hide_home_breadcrumb'] = array(
'#type' => 'radios',
'#options' => [
'0' => 'Show <em>Home</em> in breadcrumb trail (Drupal’s default behavior)',
'1' => 'Remove <em>Home</em> from breadcrumb trail',
'2' => 'Remove <em>Home</em> when it is the only breadcrumb in trail',
],
'#default_value' => theme_get_setting('hide_home_breadcrumb', 'yourtheme'),
);
}
Add the following to your theme's yourtheme.theme
file:
/**
* Prepares variables for `breadcrumb.html.twig`.
*/
function yourtheme_preprocess_breadcrumb(&$variables){
// Remove 'Home' from breadcrumb trail based on theme settings variable.
//
// Possible values:
// - 0: do not remove
// - 1: remove
// - 2: remove if its the only item
$hide_home_breadcrumb = theme_get_setting('hide_home_breadcrumb', 'yourtheme');
if ($hide_home_breadcrumb == '1' && count($variables['breadcrumb'])) {
array_shift($variables['breadcrumb']);
}
elseif ($hide_home_breadcrumb == '2' && count($variables['breadcrumb']) == 1) {
array_shift($variables['breadcrumb']);
}
}
If you want the Home button to be disabled by default when the theme is installed, add the following to your theme's yourtheme.settings.yml
:
# Remove 'Home' in breadcrumb trail if its the only item.
hide_home_breadcrumb: '2'
If you're working with an existing site, and are using Drupal Configuration Syncing with Drupal 8, you should also add/modify the yourtheme.settings.yml
file in the sync directory, and run drush cim sync
.
In templated.php ask if "Home page" and be language specific. Take out ( && $language_url->languag**e and **global $language_url;) if you don't need language look up. Also change "/htdocs/drupal/de" in "href" to appropriate URL.
function _YOUR_THEME_NAME_breadcrumb(&$variables) {
$breadcrumb = $variables['breadcrumb'];
global $language_url;
if (drupal_is_front_page()){
return;
} elseif(!empty($breadcrumb) && $language_url->language == 'de') {
$breadcrumb[0] = '<a href="/htdocs/drupal/de">STARTSEITE</a>';
$breadcrumb = implode(' | ', $breadcrumb);
return $breadcrumb;
}
}
If you have path breadcrumbs module installed. Go to structure > Path breadcrumbs > path breadcrumbs settings, then check the "Hide breadcrumbs navigation for single breadcrumb", save configuration, refresh page. Done.